How can I have my userform label pull from a specific range based on a variable?

billyshears

Board Regular
Joined
Aug 29, 2013
Messages
61
I created a userform to bring up. I can bring up the userform by pressing button 1 or button 2.

If I press button 1, I want the userform label to read as the input from Cell A1 on the work sheet. If I press button 2, i want the label to read as the data input from Cell B1

I know how to code the userform to grab the label from a specific cell, but I cannot figure out how to make it variable based on what button I am pressing
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi,
I assume you mean a button you are pressing on worksheet to display the UserForm? if so try

VBA Code:
Sub Button1_Click()
    With UserForm1
        .Label1.Caption = Range("A1").Text
        .Show
     End With
End Sub

Sub Button2_Click()
    With UserForm1
        .Label1.Caption = Range("B1").Text
        .Show
     End With
End Sub

Adjust code as required to meet your project need.

Dave
 
Upvote 0
Yes, thanks. Where do I input that? by double clicking the label on the username form, or on the buttons?
 
Upvote 0
Yes, thanks. Where do I input that? by double clicking the label on the username form, or on the buttons?

Its the Button code if they are located on a worksheet - you place it either in your worksheet if using ActiveX buttons or in standard module if as in my example, using Form buttons
Code may need to be amended to meet your Userform & Label names if different.

Dave
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,876
Members
449,056
Latest member
ruhulaminappu

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