|
▼MAX さん:
こんばんは。
既に回答が出ていますが、このようなコードでも。
Sub SampleX()
Dim cols1 As Long, cols2 As Long, rows1 As Long
Dim sh1 As Worksheet, sh2 As Worksheet
Dim x As Long
Dim z
Dim sh2Head As Range
Set sh1 = Worksheets("Sheet1")
Set sh2 = Worksheets("Sheet2")
cols1 = sh1.UsedRange.Columns.Count
rows1 = sh1.UsedRange.Rows.Count
cols2 = sh2.UsedRange.Columns.Count
Set sh2Head = sh2.UsedRange.Resize(1)
For x = 1 To cols1
z = Application.Match(sh1.Cells(1, x).Value, sh2Head, 0)
If VarType(z) <> vbError Then
sh2.UsedRange.Columns(z).Resize(rows1).Value = sh1.UsedRange.Columns(x).Value
End If
Next
End Sub
|
|