How can I use public variable when my sub is private?

rkim01

New Member
Joined
Aug 12, 2007
Messages
25
Private Sub UnhideAll()
Worksheets("Sheet1").Rows("1:100").Select
Selection.EntireRow.Hidden = False
st.Select
End Sub

public sub DG ()
Dim st As Range
Set st = Range("a1")
end sub

Basically this is my code and I want to call st which is in public to private UnhideAll sub procedure. However it wouldn't let me unless i set st in UnhideAll procedure. runtime error '424'

How can I access public variables from private?
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
You are not declaring global variable.

1) delete Dim statement from sub DG
2) place that line on the top of any line in the page, that is general part of the module.

should look like
Code:
Dim st As Range

private sub unhideall()
.
.
end sub

public sub DG()
Set st= range("a1")
end sub
 
Upvote 0

Forum statistics

Threads
1,213,489
Messages
6,113,947
Members
448,534
Latest member
benefuexx

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