Populate Combobox from sheet with criteria

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,422
Office Version
  1. 2016
Platform
  1. Windows
Is there a way I can populate a Combobox on a Userform with values from column A but only if the cell in Column C is NOT blank?
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
This should work
Code:
Dim oneCell As Range

With Sheet1.Range("A:A")
    For Each oneCell In Range(.Cells(1, 1), .Cells(Rows.Count, 1).End(xlUp))
        With oneCell
            If CStr(.Offset(0, 2).Value) <> vbNullString Then
                ComboBox1.AddItem CStr(.Value)
            End If
        End With
    Next oneCell
End With
 
Upvote 0
If your values in Column C are constants (that is, the cell values are not produced by formulas), then you can use this code from within the UserForm's module...
Code:
  Dim Cell As Range

  For Each Cell In Sheets("Sheet1").Columns("C").SpecialCells(xlConstants).Offset(, -2)
    ComboBox1.AddItem Cell.Value
  Next
 
Upvote 0
If your values in Column C are constants (that is, the cell values are not produced by formulas), then you can use this code from within the UserForm's module...
Code:
  Dim Cell As Range

  For Each Cell In Sheets("Sheet1").Columns("C").SpecialCells(xlConstants).Offset(, -2)
    ComboBox1.AddItem Cell.Value
  Next
I do not recommend using the following code, but I know that there are some out "there" who like to see my one-liners, so the following is for "entertainment purposes" only...

Code:
ComboBox1.List = Split(Application.Trim(Join(Application.Transpose(Evaluate(Replace("IF(LEN([COLOR=#0000FF][B]Sheet1[/B][/COLOR]!C1:C#),[COLOR=#0000FF][B]Sheet1[/B][/COLOR]!A1:A#,"""")", "#", Sheets("[COLOR=#0000FF][B]Sheet1[/B][/COLOR]").Cells(Rows.Count, "C").End(xlUp).Row))))))
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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