How do I Remove Blanks from a UserForm ComboBox

coreyalaurence39

New Member
Joined
Mar 10, 2022
Messages
20
Office Version
  1. 2019
Platform
  1. Windows
I am trying to populate a UserForm ComboBox drop down list and it is also picking up the blanks that are in the column. How do I remove the blanks in the ComboBox on the UserForm. I have not found any code that has worked for this issue.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
When the data is in column A

VBA Code:
Private Sub UserForm_Initialize()
 With Range("A1", Range("A" & Rows.Count).End(xlUp))
   ComboBox1.List = Filter(Application.Transpose(Evaluate("if(" & .Address & "<>""""," & .Address & ")")), False, 0)
 End With
End Sub

or

VBA Code:
Private Sub UserForm_Initialize()
Range("A1", Range("A" & Rows.Count).End(xlUp)).Name = "ar"
ComboBox1.List = Filter([Transpose(if(ar<>"",ar))], False, 0)
End Sub
 
Upvote 0
When the data is in column A

VBA Code:
Private Sub UserForm_Initialize()
 With Range("A1", Range("A" & Rows.Count).End(xlUp))
   ComboBox1.List = Filter(Application.Transpose(Evaluate("if(" & .Address & "<>""""," & .Address & ")")), False, 0)
 End With
End Sub

or

VBA Code:
Private Sub UserForm_Initialize()
Range("A1", Range("A" & Rows.Count).End(xlUp)).Name = "ar"
ComboBox1.List = Filter([Transpose(if(ar<>"",ar))], False, 0)
End Sub
Thank you that is helpful. I apologize for not mentioning this but the data is actually in column B.
 
Upvote 0
For example:

VBA Code:
Private Sub UserForm_Initialize()
Sheets("Employee_Master").Range("A1", Sheets("Employee_Master").Range("A" & Rows.Count).End(xlUp)).Name = "ar"
ComboBox1.List = Filter([Transpose(if(ar<>"",ar))], False, 0)
End Sub
 
Upvote 0
For example:

VBA Code:
Private Sub UserForm_Initialize()
Sheets("Employee_Master").Range("A1", Sheets("Employee_Master").Range("A" & Rows.Count).End(xlUp)).Name = "ar"
ComboBox1.List = Filter([Transpose(if(ar<>"",ar))], False, 0)
End Sub
Thank you that is working just like I want it to :)

Do I have two ComboBoxes that I need to populate with different data. The other data is on a sheet called Earning_Codes. Do I just use this same code and alter it for that sheet and include it in the Private Sub UserForm Initialize?
 
Upvote 0
Yes that should work indeed
 
Upvote 0

Forum statistics

Threads
1,215,947
Messages
6,127,867
Members
449,410
Latest member
adunn_23

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