1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| Sub CopyColumnByTitle()
'Find "Name" in Row 1
Dim x As Workbook
'## Open both workbooks first:
Set x = Workbooks.Open(Application.ActiveWorkbook.Path & "\Suppliers ex Morpho.xlsx")
With x.Sheets("Database").Rows(1)
Set t = .Find("Vendor name", lookat:=xlPart)
'If found, copy the column to Sheet 2, Column A
'If not found, present a message
If Not t Is Nothing Then
Columns(t.Column).EntireColumn.Copy _
Destination:=ThisWorkbook.Sheets("Feuil2").Range("A1")
Else: MsgBox "Column Name Not Found"
End If
End With
With x.Sheets("Database").Rows(1)
Set b = .Find("Vendor account", lookat:=xlPart)
'If found, copy the column to Sheet 2, Column A
'If not found, present a message
If Not b Is Nothing Then
Columns(b.Column).EntireColumn.Copy _
Destination:=ThisWorkbook.Sheets("Feuil2").Range("B1")
Else: MsgBox "Column Name Not Found"
End If
End With
x.Close
End Sub |
Partager