I have code below which transposes column values from one particular workbook (Activeworkbook - columns O,AH and I) over to another workbook ("loader file.xls" - columns A,B,C). It works perfectly for my needs
Sub PullTrackerInfo()
'Pull info from respective column into correct column on loader file
Dim wb_mth As Workbook, wb_charges As Workbook, mapFromColumn As Variant, mapToColumn As Variant
Dim lastCell As Integer, i As Integer, nextCell As Integer, arrCopy As Variant
Set wb_mth = ActiveWorkbook
Set wb_charges = Workbooks("loader file.xls")
mapFromColumn = Array("O", "AH", "I")
mapToColumn = Array("A", "B", "C")
For i = 0 To UBound(mapFromColumn)
With wb_mth.Sheets(1)
lastCell = w.Sheets("owssvr").ListObjects("Table_owssvr").Range.Rows.Count
arrCopy = .Range(mapFromColumn(i) & 2 & ":" & mapFromColumn(i) & lastCell)
End With
With wb_charges.Worksheets(1)
nextCell = .Range(mapToColumn(i) & .Rows.Count).End(xlUp).Row + 1
.Range(mapToColumn(i) & nextCell).Resize(UBound(arrCopy), UBound(arrCopy, 2)).Value = arrCopy
End With
Next i
End Sub
What I would like to do is to go one step further, I typically have to sort the data to the correct column in order to transpose it over to the loader file. What I would like to do is move the columns data over depending on the title of the column heading ("market Code, "ID", "C Code"). See the idea below...
mapFromColumn = Array("Market Code", "ID", "C Code",
mapToColumn = Array("A", "B", "C")
For i = 0 To UBound(mapFromColumn)
With wb_mth.Sheets(1)
lastCell = w.Sheets("owssvr").ListObjects("Table_owssvr").Range.Rows.Count
arrCopy = .Range(mapFromColumn(i) & 2 & ":" & mapFromColumn(i) & lastCell)
End With
With wb_charges.Worksheets(1)
nextCell = .Range(mapToColumn(i) & .Rows.Count).End(xlUp).Row + 1
.Range(mapToColumn(i) & nextCell).Resize(UBound(arrCopy), UBound(arrCopy, 2)).Value = arrCopy
End With
Next i
End Sub
The code above does not obviously work, i've tried a couple of different tactics to no avail. If anyone could help me out that would be great. Thanks