View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default Find Row Using 3 ComboBoxes As Criteria

Yes, you need to develop a valid test. I wasn't suggesting clng for dates.
If you want to test a date I would suggest

format(c.offset(0,1).Value2, "mm/dd/yyyy hh:mm AM/PM") = _
format(cdate(cb2.Value)),"mm/dd/yyyy hh:mm AM/PM")

I realize it might be frustrating, but you need to instrument your code a
bit and see where you might be having problems - otherwise you might need to
create watch values or step through your code.

--
Regards,
Tom Ogilvy





"Minitman" wrote:

Hey Tom,

I tried that , unfortunately it didn't work

Column B is formatted as date/time (mm/dd/yyyy h:mm AM/PM).
CLng(CB2) errors out with that type mismatch error.

Is there anything else I can try?



On Wed, 19 Jul 2006 12:08:01 -0700, Tom Ogilvy
wrote:

That code should work. If it isn't you need to debug it and see why it isn't
working.

One problem could be that some of your columns where you need to match are
numbers. Values in a combobox are always strings (even if they look like
numbers). this could be your problem. In the example I set up and tested,
the second column was a number, so I converted the cb2.value like this
clng(cb2.value) = cell.offset(0,1).value

you could also do

cb2.value = cell.offset(0,2).Text

as long as you don't have special formatting applied that doesn't appear in
the combobox.

this was taken from a userform where it was working very well:

Private Sub CommandButton1_Click()
For Each c In Range("ReceiptList").Columns(1).Cells
If CB1.Value = c.Value _
And CLng(CB2.Value) = c.Offset(0, 1).Value _
And CB3.Value = c.Offset(0, 2).Value Then
TB5.Value = c.Offset(0, 3).Value
TB6.Value = c.Offset(0, 4).Value
Exit Sub
End If
Next c

End Sub