Assist with defining worksheet

bradjedis
4StarLounger
Posts: 539
Joined: 30 Mar 2010, 18:49
Location: United States

Assist with defining worksheet

Post by bradjedis »

Greetings,

I have a fairly large macro (one that I cannot share). However I think I know the direction I need to go, but not quite sure of the method.

we have defined the below,

Dim ExcelWorksheet As String

and use it like this:

ExcelWorksheet = "Tab1"

This works as expected, but I would like the macros to function on other tabs. Is there a way to have the ExcelWorksheet = "Tab1" function on the active worksheet?

Thaanks,
Brad

User avatar
HansV
Administrator
Posts: 78557
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Assist with defining worksheet

Post by HansV »

Use

ExcelWorksheet = ActiveSheet.Name
Best wishes,
Hans

bradjedis
4StarLounger
Posts: 539
Joined: 30 Mar 2010, 18:49
Location: United States

Re: Assist with defining worksheet

Post by bradjedis »

That did it! I knew it had "activeSheet", just not the rest...


Thanks,
Brad

snb
4StarLounger
Posts: 586
Joined: 14 Nov 2012, 16:06

Re: Assist with defining worksheet

Post by snb »

Refrain from using a variable and use activesheet anywhere you want to refer to the activeSheet.
Why using a variable for a variable Object reference?

PS. I never saw a macro that can't be shared.

User avatar
p45cal
2StarLounger
Posts: 151
Joined: 11 Jun 2012, 20:37

Re: Assist with defining worksheet

Post by p45cal »

re 'PS. I never saw a macro that can't be shared.'

Well, you never would, would you? unless you wrote it yourself!

snb
4StarLounger
Posts: 586
Joined: 14 Nov 2012, 16:06

Re: Assist with defining worksheet

Post by snb »

Not even then.