Public worksheet

prlondhe

Board Regular
Joined
Jan 4, 2014
Messages
54
Hi

i have 3 different worksheets used during different modules. Is there a way that i can set these worksheets as public variables and then refer to them in the modules.

Public ws1 as string
public ws2 as string
public ws3 as string

sub setvar()
set ws1=sheet(1)
set ws2=sheet(2)
set ws3=sheet(3)
end sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Code:
[COLOR=darkblue]Public[/COLOR] ws1 [COLOR=darkblue]As[/COLOR] [B]Worksheet[/B]
[COLOR=darkblue]Public[/COLOR] ws2 [COLOR=darkblue]As[/COLOR] [B]Worksheet[/B]
[COLOR=darkblue]Public[/COLOR] ws3 [COLOR=darkblue]As[/COLOR] [B]Worksheet[/B]


[COLOR=darkblue]Sub[/COLOR] setvar()
[COLOR=darkblue]Set[/COLOR] ws1 = [B]Sheets[/B](1)
[COLOR=darkblue]Set[/COLOR] ws2 = [B]Sheets[/B](2)
[COLOR=darkblue]Set[/COLOR] ws3 = [B]Sheets[/B](3)
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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