Error adding code for Combo box drop down list

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,259
Office Version
  1. 2010
Platform
  1. Windows
Hi, I have the code below but I am getting an error, the situation is I have two combo boxes in a userform and the boxes are filled in with data from my 'IN DAY LISTS' sheet, but it doesn't work when I added ComboBox1 coding below, please can you help me? I appreciate all your help with this :)

Code:
Private Sub UserForm_Initialize()
ComboBox2.RowSource = ""
    ComboBox2.List = Sheets("IN DAY LISTS").Range("D2", Sheets("IN DAY LISTS").Range("D" & Rows.Count).End(xlUp)).Value
ComboBox1.RowSource = ""
    ComboBox1.List = Sheets("IN DAY LISTS").Range("C2", Sheets("IN DAY LISTS").Range("C" & Rows.Count).End(xlUp)).Value
End With

End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
please try this:

Code:
Private Sub UserForm_Initialize()
ComboBox2.RowSource = ""
    ComboBox2.List = Sheets("IN DAY LISTS").Range("D2:D" & Sheets("IN DAY LISTS").Range("D" & Rows.Count).End(xlUp).Row).Value
ComboBox1.RowSource = ""
    ComboBox1.List = Sheets("IN DAY LISTS").Range("C2:C" & Sheets("IN DAY LISTS").Range("C" & Rows.Count).End(xlUp).Row).Value
End With
End Sub
 
Upvote 0
still the same unfortunately with the 'End With'
What did you change sorry for asking but I couldn't see it. Thank you for your help though :)
 
Upvote 0
My bad! Remove "End With"

Code:
Private Sub UserForm_Initialize()
ComboBox2.RowSource = ""
    ComboBox2.List = Sheets("IN DAY LISTS").Range("D2:[COLOR=#ff0000]D"[/COLOR] & Sheets("IN DAY LISTS").Range("D" & Rows.Count).End(xlUp).[COLOR=#ff0000]Row).[/COLOR]Value
ComboBox1.RowSource = ""
    ComboBox1.List = Sheets("IN DAY LISTS").Range("C2:[COLOR=#ff0000]C"[/COLOR] & Sheets("IN DAY LISTS").Range("C" & Rows.Count).End(xlUp).[COLOR=#ff0000]Row[/COLOR]).Value

End Sub

Or use this one with "With"

Code:
Private Sub UserForm_Initialize()
With Sheets("IN DAY LISTS")
    ComboBox2.RowSource = ""
    ComboBox2.List = .Range("D2:D" & .Range("D" & Rows.Count).End(xlUp).Row).Value
    ComboBox1.RowSource = ""
    ComboBox1.List = .Range("C2:C" & .Range("C" & Rows.Count).End(xlUp).Row).Value
End With
End Sub
 
Last edited:
Upvote 0
Alternatively
Code:
Private Sub UserForm_Initialize()
With Sheets("IN DAY LISTS")
   ComboBox2.RowSource = ""
       ComboBox2.List = .Range("D2", .Range("D" & Rows.Count).End(xlUp)).Value
   ComboBox1.RowSource = ""
       ComboBox1.List = .Range("C2", .Range("C" & Rows.Count).End(xlUp)).Value
End With

End Sub
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,761
Messages
6,180,818
Members
452,997
Latest member
gimamabe71

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