Professional code require for recorded macro

VBABEGINER

Well-known Member
Joined
Jun 15, 2011
Messages
1,232
To, All experts,
pls provide me some professional code for below line of code..So i can learn the new..

Code:
Windows("Book1.xlsm").Activate
Sheets("sheet1").Select
Range("A2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Windows("Book2.xlsm").Activate
Sheets("abc").Select
Range("A2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("A2").Select
 
Last edited by a moderator:

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Something like
Code:
Workbooks("Book1.xlsm").Sheets("sheet1").Range("A2").CurrentRegion.Copy Destination:=Workbooks("Book2.xlsm").Sheets("abc").Range("A2")
 
Upvote 0
Something like
Code:
Workbooks("Book1.xlsm").Sheets("sheet1").Range("A2").CurrentRegion.Copy Destination:=Workbooks("Book2.xlsm").Sheets("abc").Range("A2")

Hi, Thnks for your quick reply...

But it gives me an error....subscript out of range
 
Upvote 0
Do you have
1) an open workbook called Book1.xlsm
2) a sheet in the above workbook called sheet1
3) data in A2 of above sheet/workbook
4) an open workbook called book2.xlsm
5) a sheet in book2 called abc
 
Upvote 0
Hi Fluff,
This is the corrected one..
Workbooks("Book1.xls").Sheets("sheet1").Range("A2").CurrentRegion.Copy _
Destination:=Workbooks("Book2.xlsm").Sheets("abc").Range("A2")
 
Upvote 0
I'm afraid I don't understand what you mean. Could you please explain

Workbooks("Book1.xls").Sheets("sheet1").Range("A2").CurrentRegion.Copy _
Destination:=Workbooks("Book2.xlsm").Sheets("abc").Range("A2")

it giving me an error, subscript out of range..Run time error 9..

therefore, I added, 2 line above to this code..

Sheets("sheet1").Select
Range("A2").Select
Workbooks("Book1.xls").Sheets("sheet1").Range("A2").CurrentRegion.Copy _
Destination:=Workbooks("Book2.xlsm").Sheets("abc").Range("A2")
 
Upvote 0
In that case could you please answer my questions from post#4
 
Upvote 0

Forum statistics

Threads
1,214,989
Messages
6,122,622
Members
449,093
Latest member
catterz66

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