I have a macro below that opens a workbook and copies the data.
However the fields in the import data changes from time to time i.e. extra fields are added
I need my code altered so that only columns containing the following headings in row 1 are copied
Stock Number Order Number Registration Number Make
your assistance in this regard is most appreciated
However the fields in the import data changes from time to time i.e. extra fields are added
I need my code altered so that only columns containing the following headings in row 1 are copied
Stock Number Order Number Registration Number Make
Code:
Sub Open_Workbook()
ChDir ("C:\extract")
With Sheets("Vehicles")
.Range("A1:AO500").ClearContents
End With
Dim nb As Workbook, ts As Worksheet, A As Variant
Dim rngDestination As Range
Set ts = ActiveSheet
With Sheets("Vehicles")
.Select
End With
On Error Resume Next
Set rngDestination = Application.Range("'vehicles'!A1")
On Error GoTo 0
If rngDestination Is Nothing Then Exit Sub 'User canceled
A = Application.GetOpenFilename
If A = False Or IsEmpty(A) Then Exit Sub
Application.ScreenUpdating = False
Set nb = Workbooks.Open(Filename:=A, local:=True)
ThisWorkbook.Activate
nb.Sheets(1).Range("A:AO").Copy
rngDestination.PasteSpecial Paste:=xlPasteValues
rngDestination.PasteSpecial Paste:=xlPasteFormats
Application.CutCopyMode = False
nb.Close savechanges:=False 'Close the source workbook
End Sub
your assistance in this regard is most appreciated