Forum Discussion
MixMasterMike
Dec 12, 2022Copper Contributor
Using VBA to pull in data from separate workbook based on specific column order
Hi All, I currently have a macro that copy and pastes data from one workbook to a separate workbook, but it's not dynamic at the moment - meaning that if the column ordering of the source data chang...
OliverScheurich
Dec 12, 2022Gold Contributor
Sub copyandpaste()
Dim h, i, j, k, l As Long
k = Range("A1").End(xlToRight).Column
For i = 1 To k
h = Application.WorksheetFunction.Match(Cells(1, i), Sheets("Tabelle2").Range("1:1"), 0)
j = Sheets("Tabelle2").Range("i" & Rows.Count).End(xlUp).Row
For l = 2 To j
Cells(l, i).Value = Sheets("Tabelle2").Cells(l, h).Value
Next l
Next i
End SubYou can try this code to pull data based on a specific column number within the same workbook. In the attached file you can click the button in cell L2 to run the macro. If this works for you the code can be adapted in order to pull data from another workbook.