Professional code require for recorded macro

VBABEGINER

Well-known Member
Joined
Jun 15, 2011
Messages
1,284
Office Version
  1. 365
Platform
  1. Windows
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:
Do you have
1) an open workbook called Book1.xlsm
= No. I am opening this file from,
Dim fNameAndPath1 As Variant
fNameAndPath1 = Application.GetOpenFilename(FileFilter:="Excel Files (*.XLS), *.XLS", Title:="Select File To Be Opened")
If fNameAndPath1 = False Then Exit Sub
Workbooks.Open Filename:=fNameAndPath1


And, this is not .xlsm. This is .xls file.

2) a sheet in the above workbook called sheet1
= Yes.

3) data in A2 of above sheet/workbook
= Yes.

4) an open workbook called book2.xlsm
= Yes. This is already kept open with me.

5) a sheet in book2 called abc
= Yes.

 
Upvote 0

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
In that case try
Code:
ActiveWorkbook.Sheets("sheet1").Range("A2").CurrentRegion.Copy Destination:=Workbooks("Book2.xlsm").Sheets("abc").Range("A2")
Making sure that your "Book1" is active
 
Upvote 0
In that case try
Code:
ActiveWorkbook.Sheets("sheet1").Range("A2").CurrentRegion.Copy Destination:=Workbooks("Book2.xlsm").Sheets("abc").Range("A2")
Making sure that your "Book1" is active

Excellent...:pray: ....5 star rating for you...

Thanks Fluff, for your kind activeness and sharing for knowledge..

Can You also tell me about this..
Range(Cells(2, 10), Cells(LstRw, 10)).Select
Selection.ClearContents
 
Upvote 0
Can You also tell me about this..
Range(Cells(2, 10), Cells(LstRw, 10)).Select
Selection.ClearContents


Depends what the value of LstRw is
But if we assume that LstRw = 100 then, it is removing the contents of the cells J2 to J100
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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