Passing Variables between UserForm/Module 
Author Message
 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.



Sun, 10 Mar 2002 03:00:00 GMT  
 Passing Variables between UserForm/Module
Marston:

Your assessment is correct: Public declare your variable in
the Module, not the UserForm.

Tim


Quote:

> 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.

* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!


Sun, 10 Mar 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Passing UserForm Variable To Class Module

2. Passing a Variable from one Userform to another Userform

3. Passing information from UserForm to other code module

4. Pass variable to userform

5. Passing a variable through a UserForm

6. Passing variables between userforms and/or normal procedures

7. Excel 97: Pass variable from userform to Sub ?

8. Passing variables or arrays to userforms

9. Passing variables or arrays to userform objects

10. Passing a variable through a UserForm


 
Powered by phpBB® Forum Software © phpBB Group