PDA

View Full Version : Solved: Refering Sheet without using Sheet name in VBA Code



nagavineela
09-19-2010, 09:17 PM
Hi All,
How do we refer to sheets without using Sheetnames while developing the code in VBA.

For e.g., I have Sheet1 and Sheet2 with button macros. While developing the code, i have used sheetname as reference.
Requirement is if we copy Sheet1 and name as sheet3, though the logic is perfect since the sheet name in the code was Sheet1 will not work for Sheet3.

Can anyone help me in resolving how to point to the sheet without using Sheets("sheet1").....

macropod
09-19-2010, 10:27 PM
If you can be certain of the order in which the sheets will occur, you could use Sheets(1), Sheets(2), etc. Alternatively, if the code has to be run against the active sheet, you could use 'ActiveSheet'.

nagavineela
09-19-2010, 11:11 PM
Thank you so much. Working as per intended after using "ActiveSheet".

Regards,