Basic Stuff to some

  • Thread starter Thread starter Corey
  • Start date Start date
C

Corey

Being a lerner at Vb, why do i get an error from the below ?

If the Combobox2.value = a value in Range(C159:C210) then i want a message to say so !!

Private Sub ComboBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim rng As Range
With Sheets("Scheduled In")
Set rng = Range("C159:C210")
If ComboBox2.Value = rng.Cells.Value Then '<== Error here
MsgBox "Already Used"
Else
MsgBox "Done"
End If
End With
End Sub


How do i write that line then?

CTM
 
Private Sub ComboBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim rng As Range, res as variant
With Sheets("Scheduled In")
Set rng = .Range("C159:C210") ' <= include period
res = Application.Match(Combobox2.Value, rng,0)
If not iserror(res) Then '<== Error here
MsgBox "Already Used"
Else
MsgBox "Done"
End If
End With
End Sub

if Combobox2 contains a number then

res = Application.Match(cdbl(Combobox2.Value), rng,0)

the original causes a type mismatch error I suspect because you can't
compare a string to an array.
 

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

Back
Top