回答編集履歴
1
追記
test
CHANGED
@@ -73,3 +73,103 @@
|
|
73
73
|
|
74
74
|
|
75
75
|
```
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
---
|
80
|
+
|
81
|
+
追記:後から示されたやりたいことに沿って修正し、コメントも加えました。
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
```VBA
|
86
|
+
|
87
|
+
Sub sample2()
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
'日付を取得
|
92
|
+
|
93
|
+
Dim strDate As String
|
94
|
+
|
95
|
+
strDate = Sheet1.Range("D5").Value
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
'各シートの表の範囲を取得
|
100
|
+
|
101
|
+
Dim sh1 As Range, sh2 As Range, sh3 As Range
|
102
|
+
|
103
|
+
Set sh1 = Sheet1.Range("C13:X20")
|
104
|
+
|
105
|
+
Set sh2 = Sheet2.Range("C4:AZ19")
|
106
|
+
|
107
|
+
Set sh3 = Sheet3.Range("D4:V8")
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
With Application.WorksheetFunction
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
Dim sh2Row, sh2Col, sh3Row
|
116
|
+
|
117
|
+
Dim i, j
|
118
|
+
|
119
|
+
Dim shift
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
'日付からSheet2の列を取得
|
124
|
+
|
125
|
+
sh2Col = .Match(strDate, .Index(sh2, 1, 0), False)
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
'Sheet1の各行を順次処理
|
130
|
+
|
131
|
+
For i = 1 To sh1.Rows.Count
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
'Sheet1の氏名からSheet2の行を取得し、シフトパターンを取得
|
136
|
+
|
137
|
+
sh2Row = .Match(sh1.Item(i, 1), .Index(sh2, 0, 2), False)
|
138
|
+
|
139
|
+
shift = sh2.Item(sh2Row, sh2Col).Value
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
If shift = "" Then
|
144
|
+
|
145
|
+
'シフトがない場合は行を非表示
|
146
|
+
|
147
|
+
sh1.Item(i, 2).EntireRow.Hidden = True
|
148
|
+
|
149
|
+
Else
|
150
|
+
|
151
|
+
'シフトが入っている場合はSheet3から該当シフトパターンの行を取得
|
152
|
+
|
153
|
+
sh3Row = .Match(shift, .Index(sh3, 0, 1), False)
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
'Sheet3からSheet1に転記
|
158
|
+
|
159
|
+
For j = 1 To sh3.Columns.Count
|
160
|
+
|
161
|
+
sh1.Item(i, j + 1) = sh3.Item(sh3Row, j)
|
162
|
+
|
163
|
+
Next
|
164
|
+
|
165
|
+
End If
|
166
|
+
|
167
|
+
Next
|
168
|
+
|
169
|
+
End With
|
170
|
+
|
171
|
+
End Sub
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
```
|