
Passing Variables between UserForm/Module
Hi Everyone
I'm having a debug problem that I can't seem to solve.
I'm trying to create a userform that will load values into a listbox each
time it is opened. The items are added to the listbox from the same form via
a RefEdit
I'll call the user form, UserForm and the list box, ListBox
At the beginning of the UserForm code I have a statement:
Public UsrRng As Range
This range variable will hold a range of cells that the user will have
selected.
Whenever the UserForm is opened, I'd like it to load the addresses of all
the cells that have been previously added into UsrRng into the listbox on
the userform.
In my Module, I have the following code
Sub Show()
Dim Rng As Range
If UsrRng.Cells.Count > 0 Then
For Each Rng in UsrRng.Cells
UserForm.ListBox.AddItem Rng.Address
Next Rng
End If
UserForm.Show
End Sub()
Show is called from a menu item
I'm getting an error 91 (object variable not defined) on the If statement
Do I need to 1) redefine the variable UsrRng as a public range in the
module? 2) Pass the variable from subroutine to subroutine?
I thought the whole reason to have global (public) variables is so that you
don't have to re-define them and re-pass their variables around. In fact, I
don't even know how I'd pass the UsrRng to the Show() routine, especially
the first time, when its empty.