|
Sub deta()
Dim Sh1 As Worksheet, Sh2 As Worksheet
Dim forNo As Variant, toNo() As Variant
Dim setRow As Integer, cMax As Integer
Dim aRange As Range, bRange As Range
Dim toRow As Integer, toCol As Integer
Dim i As Double, foi As Double, toi As Double, n As Integer
forNo = Array("A1", "C1", "G1", "B1") 'コピー元(Sh1)のセル位置
toNo = Array("A1", "B1", "C1", "B2") 'コピー先(Sh2)のセル位置
setRow = 2 'コピー先1セットの行数
cMax = UBound(forNo)
Set Sh1 = ThisWorkbook.Sheets("シート1")
Set Sh2 = ThisWorkbook.Sheets("シート2")
Set aRange = Sh1.Range("A1").CurrentRegion '元データー範囲
'Set aRange = Intersect(aRange, aRange.Offset(1, 0)) '1行目を省く
Set aRange = Intersect(aRange, aRange.Columns(1)) 'A列に絞る
'aRangeのセル数(行数)分転記する。
Sh2.Range("A1:ZZ1000").ClearContents '転記先をクリアー?
For Each bRange In aRange
i = bRange.Rows.Row
foi = i - 1
toi = foi * setRow
Debug.Print bRange.Address, i, toi
For n = 0 To cMax
Sh2.Range(toNo(n)).Offset(toi, 0).Value = Sh1.Range(forNo(n)).Offset(foi, 0).Value
Next
Debug.Print bRange.Address, i, toi
Next
Set aRange = Nothing
Set bRange = Nothing
Set Sh1 = Nothing
Set Sh2 = Nothing
End Sub
|
|