ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   How to populate Label1.Caption with a variable's value (https://www.excelbanter.com/excel-discussion-misc-queries/185031-how-populate-label1-caption-variables-value.html)

Dave O

How to populate Label1.Caption with a variable's value
 
I have some On Change event code that triggers when a change is made
to a certain cell: the code performs VLOOKUPs and assigns the results
of the lookups to variables- call them V1, V2, V3.

The same event code opens a userform. I'd like to show the values of
V1, V2, and V3 as captions in Labels, and have the user click a radio
button to indicate his choice.

I've got this about together, but I need a hint: how do I use a
variable from the On Change event code in the user form? Is this a
matter of declaring a public variable?

Thanks

Dave Peterson

How to populate Label1.Caption with a variable's value
 
I'd use a public variable in a General module and just plop the value into it.

Then any routine--including the userform_initialize event can pick it up and do
anything it wants with it.

Just a comment...

The "on change" event is pretty old. You may want to consider using a
worksheet_change event instead. You may find it easier to use and nicer to
control.

Dave O wrote:

I have some On Change event code that triggers when a change is made
to a certain cell: the code performs VLOOKUPs and assigns the results
of the lookups to variables- call them V1, V2, V3.

The same event code opens a userform. I'd like to show the values of
V1, V2, and V3 as captions in Labels, and have the user click a radio
button to indicate his choice.

I've got this about together, but I need a hint: how do I use a
variable from the On Change event code in the user form? Is this a
matter of declaring a public variable?

Thanks


--

Dave Peterson

Dave O

How to populate Label1.Caption with a variable's value
 
That did it, Dave, thanks. I had declared the variables as Public in
the worksheet-specific code section, but declaring them in a general
module did the trick.

Thanks also for the comment about On Change- I did use a
Worksheet_Change event, but I couldn't remember the proper
nomenclature when I posted the note (in a hurry to leave) and used the
first VB phrase that came to mind. I'll have to check my Visual Basic
compiler to see if OnChange has been supplanted.

THanks again for your post~
Dave O

Dave Peterson

How to populate Label1.Caption with a variable's value
 
OnChange still works, but I think the only people who use it are using xl95 or
supporting stuff created in xl95 and afraid to bring the code into 1997's
standards <vbg.

===

If it ain't broke, don't fix it!

It's not just a phrase, it's a slogan!



Dave O wrote:

That did it, Dave, thanks. I had declared the variables as Public in
the worksheet-specific code section, but declaring them in a general
module did the trick.

Thanks also for the comment about On Change- I did use a
Worksheet_Change event, but I couldn't remember the proper
nomenclature when I posted the note (in a hurry to leave) and used the
first VB phrase that came to mind. I'll have to check my Visual Basic
compiler to see if OnChange has been supplanted.

THanks again for your post~
Dave O


--

Dave Peterson


All times are GMT +1. The time now is 10:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com