Unknown Worksheet name in macro

lhernandez

Active Member
Joined
May 22, 2006
Messages
282
I have a worksheet that needs to be inported into a workbook I am using for different projects. (One a copy of the workbook will be used for each differnt project, but using all the same macros)
i have written a macro to perform all the needed tasks, the only problem is the name of the worksheet I have referenced in my macro will not always be the same for each project.
I have no clue how to go about working with...or if its possible.
Any ideas?
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
How would you identify the worksheet to work with?

Will it be the active sheet?

Is it named using some sort of convention?

Does it have particular data on it?

Is it the last/first/nth worksheet in the workbook?
 
Upvote 0
I guess i could make it the active sheet, that would be fine. So i would reference the active sheet, in stead of the worksheet name?
 
Upvote 0
Yes, you could activate the sheet of interest and then just refer to 'ActiveSheet'. Or as Norie points out, if there's some way to specify the sheet without activating it you can assign a variable to the sheet and refer to the variable.
If you were manually performing the tasks your macro performs now, what criteria would you use to determine which sheet it is?
 
Upvote 0
I referenced the sheet name, but after building the macro I realized that it would not always have the same name as different projects have different names. I am writing this macro for other people in the department who do not know VB, so it would be easier if I could refernce something that could always be the same. How would I assign a variable to a sheet to refer to?
 
Upvote 0
Could we see your code?

To create a reference to the active sheet use this.
Code:
Set ws = ActiveSheet
To create a reference to the a named sheet use this.
Code:
Set ws = WorkSheets("SheetName")
Both of these references can then be used in the subsequent code whenever you want to refer to the worksheet.
 
Upvote 0

Forum statistics

Threads
1,226,453
Messages
6,191,136
Members
453,642
Latest member
jefals

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