How to remove the first item in a combo box

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
563
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
VBA Code:
Private Sub UserForm_Initialize()
    Me.Caption = "Maintenance Requster"
    'Me.cmbMaintPersonnel.List = Sheets("Maintenance Contact").Range("C2:C10001").Value
    
    Dim listLength As Integer
    Dim wks As Worksheet
    Dim cmbMaintList As Range
        
    Set wks = Worksheets("Maintenance Contact")
    listLength = Worksheets("Maintenance Contact").Cells(Rows.Count, "A").End(xlUp).Row '<==== finds the length of the list
    For x = 1 To listLength
        If wks.Cells(x, 1) <> "" Then '<=== ignores the blank spaces
            With cmbMaintPersonnel '<=== name of your comboBox
                .AddItem (wks.Cells(x, 3).Value) '<==== adds it to the list
            End With
        End If
    Next x
    
End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
I forgot to mention that row 1 is a header. So I would like to remove it from my combo box. Thank you.
 
Upvote 0
Use For x=2 rather than 1
 
Upvote 0
Or without a loop
VBA Code:
Private Sub UserForm_Initialize()
    Me.Caption = "Maintenance Requster"
    'Me.cmbMaintPersonnel.List = Sheets("Maintenance Contact").Range("C2:C10001").Value
    
    Dim listLength As Integer
    Dim wks As Worksheet
        
    Set wks = Worksheets("Maintenance Contact")
    listLength = wks.Cells(Rows.Count, "A").End(xlUp).Row '<==== finds the length of the list
    With wks.Range("A2:A" & listLength)
      cmbMaintPersonnel.List = filter(wks.Evaluate("transpose(if(" & .Address & "<>""""," & .Offset(, 2).Address & ",""#@}""))"), "#@}", False)
   End With
End Sub
 
Upvote 0
Not sure what happened, but now I am getting a Runtime error -2147024809 (80070057); Invalid Argument
 
Upvote 0
With which code & on which line?
 
Upvote 0

Forum statistics

Threads
1,214,632
Messages
6,120,655
Members
448,975
Latest member
sweeberry

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