Which variable to use?

  • Thread starter Thread starter Rachael
  • Start date Start date
R

Rachael

hello there! I have a column of data which i want to filter using
combo box. However,numbers do not occur in the combo box list when i
need to select which item to filter. Do i define the variable as
something else or something is wrong with the code? I need the combo
box to read in both text and numbers. Thanks!

Here's the code:

Private Sub filterp_Click()

Dim Class As Variant

Class = ComboBox1.Value
Sheets("Sheet1").Range("A2:AE65000").Select
Selection.AutoFilter Field:=1, Criteria1:=Class

End Sub
 
You don't show the code that populates the combobox, so it would be hard to
say why no numbers are in the combobox list.
 
sorry abt that..here it is:

Set Coll = New Collection

With ComboBox1
.Clear

For Each cell In Range("A2:A65000")

If cell.Value <> "" Then
Err.Clear
Coll.Add cell.Value, cell.Value
If Err.Number = 0 Then .AddItem cell.Value
End If

Next cell

End Wit
 
Rachael,
I suspect your problem is from the type coercion (<number> to string) that
occurs when you use .AddItem.
Read the combobox value leaves it as a string, which is maybe not what you
want in your criteria.
Try CLng or CDbl to get the <number> back.

NickHK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top