VBA changing a user form label based on cell value?

Cease

Board Regular
Joined
Dec 28, 2010
Messages
112
Hi!
Is there any way to change a label in a user form based on the value of a cell?

I'm trying to link a series of labels to a small range of cells that change based on a data-validation drop box.

I've tried finding info, but I can't seem to find the right place.

The code I've tried so far without result is:
Code:
Private Sub Label3_Click()
    Me.Label13.Caption = ActiveSheet.Range("BQ15")
End Sub

Any advice, direction, or a "no that's not possible" would be greatly appreciated!
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hi,

What error do you get?

From that code you are setting Label 13's caption to Range BQ15 whenever you click on Label 3. Is this correct?
 
Upvote 0
Thanks,

It doesn't return any error (fortunately), but the label itself doesn't change either.

I'm hoping to have just the label be changed, or be the specific value (in this case cell BQ15).

So no action once the form is open, just for this value to change.

I'm super new to userforms, maybe it's in the "Label13_Click()" part then?

Thanks again for the response and your time.
 
Upvote 0
You are running the code in Label 3_Click though (not 13), maybe that's the problem as it should work..
 
Upvote 0
I'm still not having anything show with this.
I altered the code to be more sheet-specific, hoping that might do it:

Code:
Private Sub Label13_Click()
    Me.Label13.Caption = Sheet2.Range("bq15")
End Sub

The label is still completely blank when I run the form.

Do you think it could be one of the label's properties?
In the property Box I have it blank beside the Caption space, should that be changed?

It's probably something very obvious I'm overlooking :/

Thanks again for you time and help!
 
Upvote 0
I found if I change the label to a text box, I can change the ControlSource to a named range and that does what I need.

Thanks so much for your time again!
Great quotes btw, I love the whole Hitchiker's Guide series...
 
Upvote 0
When exactly do you want this to happen?

You shouldn't use the click event of a control like a label to set it's caption.

If you wanted you could put values in all the labels on the form in the forms initializiation event.

That of course would put the captions in when the form opens.

If you want to change the labels based on something selected/clicked on the userform then you could use one of the events for the control clicked/whatever.

For example, if it was a combobox or listbox you could use the change event, and you could use the value selected to set the labels if needed.
 
Upvote 0
If you wanted you could put values in all the labels on the form in the forms initializiation event.

That of course would put the captions in when the form opens.

That would be an awesome solution too, more of what I'm looking for.
Is that at the beginning of the code, all of the
Dim ___ ___ ?

Any way you could show me a small example of what this might look like?

Thank you!
 
Upvote 0
Cease

I notice you seem to have 2 threads on the go which seem to be covering similar topics.

I think for both of them an explanation (in words) of what you are trying to do, perhaps with some example data, might help.:)
 
Upvote 0
This wasn't originally my question (I just sort of shang-hai'd it). I liked your answer to Cease & I am trying to do something similar. I understand the part about putting it in the forms Initialization code as opposed to the event click code, but I seem to still be having difficulty w/ that. I'm using code:
Sub Open_Leaseform()
LEASFORM.Show
Me.LEASFORM.Label1.Caption = Sheet10.Range("E4")
End Sub

What am I doing wrong?
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,742
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top