coy and paste

agog12

Board Regular
Joined
Jan 23, 2018
Messages
104
all files are located same place

vba is placed in a sepearte file c.xlsx

copy all the data from column A TO COLUMN H complete data from a.xlsx and paste it to b.xlsx in same columns

save and close the b.xlsx and a.xlsx

i need to do the same by vba
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
VBA Code:
Sub CopyData()
 Dim w1 As Workbook, w2 As Workbook
 Set w1 = Workbooks.Open("C:\a.xlsx") ' change the file path
 Set w2 = Workbooks.Open("C:\c.xlsx") ' change the file path
w2.Worksheets(1).Range("A1:H" & w2.Worksheets(1).Rows.Count) = _
w1.Worksheets(1).Range("A1:H" & w1.Worksheets(1).Rows.Count).Value

With w1: .Save: .Close: End With
With w2: .Save: .Close: End With

End Sub
 
Upvote 0
in the last it is pasting this type of data and at the top it is pasting correct data plz recheck the code sir
 

Attachments

  • problem.PNG
    problem.PNG
    39 KB · Views: 5
Upvote 0
Please note that by the OP's responses in another thread this issue appears to be resolved, please see the link below.
 
Upvote 0

Forum statistics

Threads
1,215,440
Messages
6,124,882
Members
449,193
Latest member
PurplePlop

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