User form problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dear all,

I follow a book's example which teaches how to transfer the data (Name &
Sex) from an user form onto a spreadsheet. I follow the procedures
step-by-step but when I clicked the "OK" button which executives the transfer
action, a compile error occurred stating "variables not defined" and
highlighted the wording "NextRow =" in the VBA code below. Please kindly
advise what's wrong with the code and how to remedy it. Thanks.

Sheets("Sheet1").Activate

NextRow = _
Application.WorksheetFunction.CountA(Range("A:A")) + 1
Cells(NextRow, 1) = TextName.Text

If OptionMale Then Cells(NextRow, 2) = "Male"
If OptionFemale Then Cells(NextRow, 2) = "Female"
If OptionUnknown Then Cells(NextRow, 2) = "Unknown"

TextName.Text = ""
OptionUnknown = True
TextName.Text.SetFocus
 
If you get a Variable Not Defined error, it means exactly that -- you
haven't declared the variable. At the beginning of the procedure, after the
Sub or Function statement, declare the variable:

Dim NextRow As Long


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com
(email address is on the web site)
 
Hi Chip,

Thanks for your help and it works. As I'm just a VBA beginner, please
tolerate my stupid question.

All the best. Regards.
 
We tolerate all kinds of questions -- we're a nice group of people. As an
aside, you posted your question in the worksheet.function newsgroup. It
would have been more appropriate to post in the programming group, since it
was a programming/VBA related question.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com
(email address is on the web site)
 
Back
Top