|
▼マリモ さん:
たぶん、勘違いはもうないと思いますが(?)
1行目の年齢はC列から横にあるという前提です。
Sub Sample2()
Dim x As Long
Dim y As Long
Dim i As Long
Dim j As Long
Dim k As Long
Dim z As Long
Dim aCode As String
Dim aName As String
Dim mf As String
Dim w() As Variant
With Sheets("Sheet1")
y = .Range("A" & .Rows.Count).End(xlUp).Row
x = .Cells(1, .Columns.Count).End(xlToLeft).Column
ReDim w(1 To .Rows.Count, 5)
For i = 2 To y Step 2
aCode = .Cells(i, "A").Value
aName = .Cells(i + 1, "A").Value
For z = i To i + 1
mf = .Cells(z, "B").Value
For j = 3 To x
k = k + 1
w(k, 1) = aCode
w(k, 2) = aName
w(k, 3) = mf
w(k, 4) = .Cells(1, j).Value '1行目の年齢
w(k, 5) = .Cells(z, j).Value 'このデータの人数
Next
Next
Next
End With
With Sheets("Sheet2")
.Cells.ClearContents
.Range("A1").Resize(k, UBound(w, 2)).Value = w
.Select
End With
MsgBox "組み換え終了です"
End Sub
|
|