Populate a UserForm Combo Box with the last selection

JeffGrant

Well-known Member
Joined
Apr 7, 2021
Messages
558
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I have a userform with a combobox that is populated from a named range. The default first entry in the combobox is the first row of the named range. All good there.

However, the workbook calls for the same combobox entry to be recalled several times, which I have a reasonable solution for.

I would like to remove an extra step (and data entry error) by having the last selection appear in the combobox area instead of the the first row in the named range.

I see this is achievable in Access, but I cant find a solution in Excel.

Can this be achieved and if so, how?

Thanks in advance for your help.

Jeff
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
I would like to remove an extra step (and data entry error) by having the last selection appear in the combobox
If that last selection was stored in a sheet in a column, then you can get the data from the last row of that column and put it in the combobox.
 
Upvote 0
Hi Dante, thanks for that.

I populate the combobox with this code:

VBA Code:
   With ThisWorkbook.Worksheets("Condition")
        ComboBox1.List = .Range("J2", .Range("J2").End(xlDown)).Value
        frm_Conditions.Label1 = Sheet25.Range("l2").Value
   End With

where Sheet25.Range("l2").Value is the last seleted combobox entry - No Drama.

So my question becomes: How do I make the value in Sheet25.Range("l2").Value become the value seen in the combobox in stead of the first entry in the Range as being the value seen in the combo box?

If I set Sheet25.Range("l2").Value as the RowSource in the properties of the combobox, then I immediately get ths error.....

1655543507683.png


and pressing the OK, removes the Sheet25.Range("l2").Value from the RowSource property.

Thanks for your help.
 

Attachments

  • 1655543526336.png
    1655543526336.png
    5.1 KB · Views: 19
Upvote 0
I guess you know "Row Source" is one way to fill combobox and using "List" property to fill combobox is another way.
So, if you change the way of filling combobox you need to clear data.
ComboBox1.RowSource="" or ComboBox1.Clear
Here is example if may helps.
VBA Code:
Private Sub ComboBox1_Change()

   Sheet25.Range("L2").Value = ComboBox1.Text
   frm_Conditions.Label1 = ComboBox1.Text
  
End Sub

Private Sub UserForm_Initialize()
 
    With ThisWorkbook.Worksheets("Condition")
'case  the combobox is almost populared with range
        If Not ComboBox1.RowSource = "" Then ComboBox1.RowSource = ""
'case  the combobox is almost populared with list
'        If ComboBox1.ListCount > 0 Then ComboBox1.Clear
        ComboBox1.List = .Range("J2", .Range("J2").End(xlDown)).Value
        frm_Conditions.Label1 = Sheet25.Range("L2").Value
        ComboBox1.Text = Label1.Caption
   End With

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

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