PDA

View Full Version : UserForms and Public Vars



Saladsamurai
09-09-2009, 03:45 PM
Here is what I am trying to do:

The user clicks a button on Worksheet1

A UserForm Pops up where they enter data

The code determines the next empty row on WorkSheet2 and plugs
the entered data into that Row.

A second UserForm automatically pops up; the user enters more data which is
then plugged into WorkSheet3 on "NextRow."

This goes on for a few more Worksheets and UserForms.

I would like the variable "NextRow" to be used throughout all of the UserForms.

I declared it Public NextRow as Long ABOVE the line Private Sub OKButton_Click

on the first UserForm. But when the second UserForm opens and I enter data on it and hit OK I get an Error: Var not Defined and the degub leads to "NextRow."

So in short, "NextRow is Defined outside of Private Sub OKButton_Click on the FIRST UserForm and works in the First USERFORM, but does not work in the SECOND UserForm.

How do I pass a variable and its current value between UserForms?

Bob Phillips
09-09-2009, 04:11 PM
Put it in a standard code module, not the userform code module.

Saladsamurai
09-09-2009, 04:30 PM
Awesome! Thanks!