exclude header in combo box

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,074
Office Version
  1. 2019
Platform
  1. Windows
I have the code that fills the combo box with names. Problem if there are no names, the header is displayed in the combo box. If there are names, the header does not show. I would like to exclude the header if there are no names populating the combo box.

VBA Code:
cbName.Clear
For Each rCell In Wks.Range("A7", Wks.Cells(Rows.Count, "A").End(xlUp))
    If Not Dic.exists(rCell.Value) Then
        Dic.Add rCell.Value, Nothing
    End If
Next rCell

For Each Key In Dic
    cbName.AddItem Key
Next
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Try
VBA Code:
If Dic.Count > 1 Then
    For Each key In Dic
        cbName.AddItem key
    Next
End If
 
Upvote 0
It still shows the header...

1591344871920.png
 
Upvote 0
How about
VBA Code:
cbname.Clear
X = wks.Cells(Rows.Count, "A").End(xlUp).Row
If X < 7 Then Exit Sub
For Each rCell In wks.Range("A7:A" & X)
    If Not dic.Exists(rCell.Value) Then
        dic.Add rCell.Value, Nothing
    End If
Next rCell
cbname.List = dic.Keys
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,446
Messages
6,124,904
Members
449,194
Latest member
JayEggleton

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