|
-
May 16th, 2013, 03:34 AM
#7
Re: [RESOLVED] Compare rows and copy to new sheet (VBA)
 Originally Posted by jmcco002
Your code is EXACTLY what I needed for a macro I am creating at work. However, how would I change the SourceSheet to the active workbook and active worksheet, which will not always be named sheet1? Also, how do I change the DestinationSheet to a different workbook?
Thanks for writing the above code.
You can use ActiveWorkbook.ActiveSheet in that case.
Code:
Set SourceSheet = ActiveWorkbook.ActiveSheet
Same way you can change the DestinationSheet to some other sheet. You will need to know either the sheet name, or the ordinal position etc.
Here are various ways to reference any worksheet/worksheet:
ActiveWorkBook --> The workbook that is active.
ThisWorkBook --> The workbook in which this macro is running from.
ActiveSheet --> The active sheet
Sheets("SheetName") --> The sheet "SheetName". e.g. Sheets("Sheet1"), Sheets("Sheet2")
Sheets(SheetNumber) --> The sheet at the position specified by SheetNumber. e.g. Sheets(1), Sheets(2)
If you don't prefix WorkBook before WorkSheet, then the ActiveWorkBook is assumed.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|