Inserting value into a ComboBox

Chopper50

New Member
Joined
Mar 14, 2013
Messages
30
I have already built my ComboBox list from a column. What I need help with is when I click on a button, it runs code to open a userform. Based on date and time, I want to populate a ComboBox with a value so the user doesn't have to type it in, but can change it based on different circumstances. I get an error on the ' Me.Shift = Shift_Ltr' line. I've tried multiple different things before posting. So based on the outcome of my date and time, I want to load Shift_Ltr into the ComboBox named "Shift" on my userform. From there the user can change it if necessary.


VBA Code:
Sub Show_Sort_Entry_Form()
Dim Entry_Time, Entry_Date As Date
Dim Shift_Ltr As String

Entry_Time = Hour(Now()) & ":" & Minute(Now())
Entry_Date = Month(Now()) & "/" & Day(Now()) & "/" & Year(Now())

If (Entry_Time > "8:00" And Entry_Time < "20:00") Then
    Shift_Ltr = ThisWorkbook.Sheets("Data").Range("K:K").Find(Entry_Date).Offset(, 1).Value
Else
    Shift_Ltr = ThisWorkbook.Sheets("Data").Range("K:K").Find(Entry_Date).Offset(, 2).Value
End If
Sort_Entry_Form.Show vbModeless

    Me.Shift = Shift_Ltr

End Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
I've found all sorts of things about setting up a combo box but I'm not sure why I can't write to 1. I have to a textbox but it doesn't seem the same code will work.
 
Upvote 0

Forum statistics

Threads
1,216,092
Messages
6,128,782
Members
449,468
Latest member
AGreen17

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