|
自分も作ってみました。
Excel2000以降なら動作すると思います。
データのあるSheet名は"Data"としてます。
左端に日付のシートが作成されます。
直しながら作っていたらインデントがグチャグチャに・・・・
読み辛くてゴメンナサイ。
'初期設定
Const Cell_W = 4 'セル幅
Const Cell_H = 16 'セル高さ
Const Shp_H = 12 'オートシェイプの太さ < セルの高さの範囲内で指定
Const St = "C4" 'オートシェイプの開始セル
Sub Shp_Test()
'初期設定エラーチェック
If Shp_H > Cell_H Then MsgBox "設定エラー": Exit Sub
Dim i, r, Shp_r As Long
Dim Ans As Variant
Dim Shp_Cl As Integer
Dim In_T, Out_T As Double
Dim Gap_T, Shp_T, Shp_L, Shp_W As Single
Dim St_T, St_L As Single
Dim Total_W As Single
Dim St_R As Range
Dim Tar_Sh As Worksheet
Dim MyShp As Shape
Dim Room As Integer
Ans = InputBox("作成する日付を入力してください(yyyy/mm/dd)", "作成日")
'Ans = "2006/05/01"
Ans = CDate(Ans)
Gap_T = (Cell_H - Shp_H) / 2
Total_W = Cell_W * 24
Worksheets.Add Before:=Worksheets(1)
Worksheets(1).Name = Format(Ans, "yyyymmdd")
Set Tar_Sh = Worksheets(1)
With Tar_Sh
Set St_R = .Range(St)
'24時間5行分の範囲で整形
.Range(St_R, St_R.Offset(5, 23)).ColumnWidth = Cell_W
.Range(St_R, St_R.Offset(5, 23)).RowHeight = Cell_H
St_T = St_R.Top
St_L = St_R.Left
Total_W = St_R.Width * 24
For i = 0 To 23
St_R.Offset(-1, i).Value = i
Next i
.Range(St_R.Offset(-1, 0), St_R.Offset(-1, 23)).HorizontalAlignment = xlLeft
End With
'オートシェイプ作成
With Worksheets("Data")
r = .Range("A65536").End(xlUp).Row
Shp_r = -1: Room = 0 '補正値
For i = 2 To r
If .Cells(i, 3).Value = Ans Or .Cells(i, 5).Value = Ans Then
If Room <> .Cells(i, 2).Value Then
Room = .Cells(i, 2).Value
Shp_r = Shp_r + 1
Shp_T = (Cell_H * Shp_r) + Gap_T + St_T
St_R.Offset(Shp_r, -1) = "部屋No." & Room
End If
If WorksheetFunction.Even(i) = i Then
Shp_Cl = 13
Else
Shp_Cl = 11
End If
If .Cells(i, 3).Value = Ans Then
In_T = .Cells(i, 4).Value
Else
In_T = 0
End If
If .Cells(i, 5).Value = Ans Then
Out_T = .Cells(i, 6).Value
Else
Out_T = 1
End If
Shp_L = In_T * Total_W + St_L
Shp_W = (Out_T - In_T) * Total_W
Set MyShp = Tar_Sh.Shapes.AddShape(msoShapeRectangle, Shp_L, Shp_T, Shp_W, Shp_H)
With MyShp.Fill
.ForeColor.SchemeColor = Shp_Cl
.Visible = msoTrue
.Solid
End With
Set MyShp = Nothing
End If
Next i
End With
Set Tar_Sh = Nothing
End Sub
|
|