Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Newbie Question - Excel VBA

Have written some elementary VBA code in an excel spreadsheet with a
UserForm that shows on demand with some calculated output using some
of spreadsheets cells as input.

Please excuse my terminology, I am embarrased enough to try to even
ask.

The problem is, that I have a command button on the UserForm. I cannot
seem to get the variables in the main "sheet1" or Worksheet(?) code to
pass to the command button code for the UserForm (click event).

How can I call them up to the UserForm CommandButton code please ?

If this makes sense to anybody I'd appreciate a response.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Newbie Question - Excel VBA

The click event of the command button does not accept arguments because it
is not normally called from another routine. If you want to establish some
condition that the button's code will react to, you might declare a public
variable (or more than one) at the top of the general module (not a sheet,
workbook or userform module) outside any procedure.

Public myvar as long

then set the value for this variable from your routine. The click event can
have code that looks at this variable

Private Sub commandbutton1_Click()
if myvar = 3 then
msgbox "Myvar is 3"
else
msgbox "Myvar is not 3"
end if
End Sub


--
Regards,
Tom Ogilvy


"Hambone" wrote in message
om...
Have written some elementary VBA code in an excel spreadsheet with a
UserForm that shows on demand with some calculated output using some
of spreadsheets cells as input.

Please excuse my terminology, I am embarrased enough to try to even
ask.

The problem is, that I have a command button on the UserForm. I cannot
seem to get the variables in the main "sheet1" or Worksheet(?) code to
pass to the command button code for the UserForm (click event).

How can I call them up to the UserForm CommandButton code please ?

If this makes sense to anybody I'd appreciate a response.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Newbie Question - Excel VBA

Thanks Tom that sorted it. I was trying to declare the public variable
inside a workbook module, and not in the general one...


"Tom Ogilvy" wrote in message ...
The click event of the command button does not accept arguments because it
is not normally called from another routine. If you want to establish some
condition that the button's code will react to, you might declare a public
variable (or more than one) at the top of the general module (not a sheet,
workbook or userform module) outside any procedure.

Public myvar as long

then set the value for this variable from your routine. The click event can
have code that looks at this variable

Private Sub commandbutton1_Click()
if myvar = 3 then
msgbox "Myvar is 3"
else
msgbox "Myvar is not 3"
end if
End Sub


--
Regards,
Tom Ogilvy


"Hambone" wrote in message
om...
Have written some elementary VBA code in an excel spreadsheet with a
UserForm that shows on demand with some calculated output using some
of spreadsheets cells as input.

Please excuse my terminology, I am embarrased enough to try to even
ask.

The problem is, that I have a command button on the UserForm. I cannot
seem to get the variables in the main "sheet1" or Worksheet(?) code to
pass to the command button code for the UserForm (click event).

How can I call them up to the UserForm CommandButton code please ?

If this makes sense to anybody I'd appreciate a response.

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
Real Newbie newbie question Dave New Users to Excel 0 January 10th 07 07:55 PM
Simple excel question for newbie Opa Excel Worksheet Functions 4 November 2nd 06 03:29 AM
Newbie Question - Subtraction Formula Question [email protected] Excel Discussion (Misc queries) 3 May 5th 06 05:50 PM
Newbie question about accessing Excel sheet from the web Patrick[_10_] Excel Programming 0 August 10th 04 06:50 PM
A newbie question Forms - Input and Output from an Excel Worksheet NewRipper Excel Programming 2 April 20th 04 12:16 AM


All times are GMT +1. The time now is 04:48 PM.

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

About Us

"It's about Microsoft Excel"