Copy Paste of column

L

Legacy 450448

Guest
vba code will be placed in a seperate file macro.xlsm
copy data from sample1.xls to sample2.xlsx
sheet name can be anything
all files are located in same place
vba code has to open the file and copy complete column B and column H and column J of sample1.xls and paste it to sample2.xlsx in column A, column B, Column C (column B of sample1.xls to column A of sample2.xls, column H of sample1.xls to column B of sample2.xlsx ,column J of sample1.xls to column C of sample2.xlsx)
save and close the file
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Try this

Code:
Sub Copy_Columns()
  Dim wb1 As Workbook, wb2 As Workbook, wPath As String
  '
  wPath = ThisWorkbook.Path & "\"
  Set wb1 = Workbooks.Open(wPath & "sample1.xls")
  Set wb2 = Workbooks.Open(wPath & "sample2.xlsx")
  wb1.Sheets(1).Range("B:B, H:H, J:J").Copy wb2.Sheets(1).Range("A1")
  wb1.Close False
  wb2.Close True
End Sub
 
Upvote 0
I'm glad to help you. I appreciate your kind comments.
 
Upvote 0

Forum statistics

Threads
1,215,459
Messages
6,124,947
Members
449,198
Latest member
MhammadishaqKhan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top