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)- Sub CopyColumns()
- Dim wbTo As Workbook
- Dim DestSht As Worksheet
- Dim rRng As Range
- Dim lRw As Long
- Set wbTo = Workbooks(“other workbook name.xlsx”)
- Set DestSht = wbTo.Sheet1
- With wbTo.Sheet1
- lRw = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
- End With
- Set rRng = ActiveSheet.Range(“A1”).CurrentRegion
- Set rRng = rRng.Offset(1).Resize(rRng.Rows.Count - 1, rRng.Columns.Count)
- rRng.Columns(1).Copy DestSht.Cells(lRw, 1)
- rRng.Columns(3).Copy DestSht.Cells(lRw, 2)
- rRng.Columns(5).Copy DestSht.Cells(lRw, 3)
- End Sub
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.