how to Append selected columns to new work book according to workbook column names
- tharusha
- Thread is marked as Resolved.
-
-
-
Cannot manipulate data in a picture. Suggest you upload a sample file and a mocked up solution that we can work with and provide a solution.
-
Hi alansidman
plz find the two attachment -
It's much easier to provide code like this if a workbook is provided.
This is untested
Code
Display MoreSub 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
-
-
-
-
Pleased to help.
-
-
What's the name of the destination sheet?
-
Thanks you i found it dim as worksheet was wrong
-
Just noticed it should be
Code
Display MoreOption Explicit 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 DestSht 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
-
-
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!