Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 158
Default User form problem

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
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 7,247
Default User form problem

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)

"Freshman" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 158
Default User form problem

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.

"Chip Pearson" wrote:

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)

"Freshman" wrote in message
...
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




  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 7,247
Default User form problem

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)

"Freshman" wrote in message
...
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.

"Chip Pearson" wrote:

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)

"Freshman" wrote in message
...
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






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
User Form: Consecutive numbering Sabine Excel Worksheet Functions 1 September 18th 06 09:07 PM
Filter Excel Pivot, based on user entry form Jayco Excel Discussion (Misc queries) 1 August 16th 06 06:07 PM
Baffling! Spreadsheet Data Form Size Jim Excel Discussion (Misc queries) 0 May 4th 06 07:41 PM
user form question: text box to display result BigPig Excel Worksheet Functions 0 February 25th 06 08:17 PM
User Form in VB = TextBox Kel Excel Discussion (Misc queries) 1 August 11th 05 12:26 AM


All times are GMT +1. The time now is 08:42 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"