sheet7のB2からD列最終行までの範囲を連想配列を使って、sheet14に結果を表示させています。
sheet7のB2からD列最終行までの範囲を連想配列を使って、sheet14に結果を表示させています。 sheet14の行を1行ずつ増やし、セル結合することになり、結果に表示されるのが、半分になりました。resizeの書いたコードをどのように修正したらよいか分かりません。ご教示をよろしくお願いします。 sub sample Dim i As Long, D, dic As Object Set dic = CreateObject("Scripting.Dictionary") Set dic2 = CreateObject("Scripting.Dictionary") With Sheet7 frow = .Cells(Rows.Count, 2).End(xlUp).Row If frow <> 1 Then D = .Range("B2", .Cells(Rows.Count, 4).End(xlUp)) For i = 1 To UBound(D) dic(D(i, 1)) = D(i, 2) dic2(D(i, 1)) = D(i, 3) Next Else MsgBox "データが入力されていません。" Exit Sub End If End With With Sheet14 frow = .Cells(Rows.Count, 4).End(xlUp).Row .Cells(11, 3).Resize(dic2.Count) = Application.Transpose(dic2.items) .Cells(11, 4).Resize(dic.Count) = Application.Transpose(dic.Keys) .Cells(11, 5).Resize(dic.Count) = Application.Transpose(dic.items) End With end Sub
Visual Basic・118閲覧・50
ベストアンサー
Dictionaryを使う必要はなく配列だけでいいと思います。 Sub test() Dim frow As Long Dim tbl As Variant Dim i As Integer Dim j As Long Dim col As Variant col = Array(3, 1, 2) With Worksheets("Sheet7") frow = .Cells(Rows.Count, 2).End(xlUp).Row If frow = 1 Then MsgBox "データが入力されていません。" Exit Sub End If tbl = .Range("B2:D" & frow) End With With Worksheets("Sheet14") For i = 1 To 3 For j = 1 To UBound(tbl) .Cells(j * 2 + 9, i + 2).Value = tbl(j, col(i - 1)) Next j Next i End With End Sub
質問者からのお礼コメント
コードありがとうございます。助かりました。
お礼日時:5/19 7:52