Using Command Buttons and UserForm Lists in Conjunction

curleyy

New Member
Joined
Mar 4, 2013
Messages
8
Hi all,

I have a macro running in which I am using a UserForm with a dropdown list. The list has three options (pulled from sheet called "Daily").
The operator is required to select one from the list and then continue or cancel.

The command button to continue is required to copy the option selected by the operator and copy it to cell "AZ1" on sheet "Daily".
I cannot get the code for the command button to work;
Sub cmdAdd_Click()
Dim LastRow As Object
Set LastRow = Sheet1.Range("AZ1").End(xlUp)
LastRow.Offset(1, 0).Value = TextBox1.Text
End Sub


Any suggestions on the code or otherwise? I'm open to anything at this stage!

Thanks in advance!!
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Why are you referring to a textbox and not a combobox?

Also, why are you starting in row 1 to find the last row? Doing that you'll always end up in row 1.

Try starting from the bottom.
[cod]e
Set LastRow = Sheet1.Range("AZ" & Rows.Count).End(xlUp)
[/code]
 
Upvote 0
Why are you pasting the selected option in Range AZ1? Is it because that is how you are transferring it back to the Macro? If so, I would declare a public variable in your macro, such as:
Code:
Public optSelection
and then set it equal to the selected option upon cmdAdd_Click. Once something is declared publicly, it can be referred to anywhere in workbook.

Assuming you are using a listbox on your userform, your cmdAdd_Click code could look something like:
Code:
Private Sub CmdAdd_Click()
If ListBox1.Value <> "" Then optSelection = ListBox1.Value
UserForm1.Hide
End Sub
Now your macro will have the selected option saved as optSelection.
 
Upvote 0
Why are you referring to a textbox and not a combobox?

Also, why are you starting in row 1 to find the last row? Doing that you'll always end up in row 1.

Try starting from the bottom.
Code:
Set LastRow = Sheet1.Range("AZ" & Rows.Count).End(xlUp)
 
Upvote 0

Forum statistics

Threads
1,223,155
Messages
6,170,405
Members
452,325
Latest member
BlahQz

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