How to Append selected columns to new work book according to workbook column names using VBA

hi i have two excel files i need to append only selected columns to another wordbook sheet how can i do that (column name might be change but the data are same)

Appendingfile.xlsx (8.8 KB) Mainfile.xlsx (9.0 KB)

  1. Sub CopyColumns()
  2. Dim wbTo As Workbook
  3. Dim DestSht As Worksheet
  4. Dim rRng As Range
  5. Dim lRw As Long
  6. Set wbTo = Workbooks(“other workbook name.xlsx”)
  7. Set DestSht = wbTo.Sheet1
  8. With wbTo.Sheet1
  9. lRw = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
  10. End With
  11. Set rRng = ActiveSheet.Range(“A1”).CurrentRegion
  12. Set rRng = rRng.Offset(1).Resize(rRng.Rows.Count - 1, rRng.Columns.Count)
  13. rRng.Columns(1).Copy DestSht.Cells(lRw, 1)
  14. rRng.Columns(3).Copy DestSht.Cells(lRw, 2)
  15. rRng.Columns(5).Copy DestSht.Cells(lRw, 3)
  16. End Sub

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.