|
▼初心者です。 さん:
>ただ、貼り付けのBシートは、B列から項目があり、
>A列には貼り付けたデータのナンバリングが入ります。
ナンバリングの意味がわかりませんが?
Sub test()
Dim wsFrom As Worksheet, wsTo As Worksheet
Dim rngFrom As Range, rngTo As Range
Dim app As Application
Dim v, k, m
Dim n As Long
Set wsFrom = Worksheets("A")
Set rngFrom = wsFrom.Cells(1).CurrentRegion
Set rngFrom = Intersect(rngFrom, rngFrom.Offset(1))
v = rngFrom.Resize(, rngFrom.Columns.Count + 1).Value
Set wsTo = Worksheets("B")
wsTo.UsedRange.Offset(1).ClearContents
Set rngTo = wsTo.Cells(1).CurrentRegion
Set app = Application
m = app.XMatch(rngTo.Value, rngFrom.Rows(0))
m = app.IfError(m, UBound(v, 2))
n = UBound(v, 1)
v = app.Index(v, app.Sequence(n), m)
Set rngTo = rngTo.Rows(2).Resize(n)
rngTo.Value = v
rngTo.Columns(1) = app.Sequence(n)
End Sub
|
|