Using OR in VBA, - type mismatch?

R

Ross

hi,
i have this code:

If Worksheets("1").Cells(acrow, 4).Value = "IB2" Or "IBC"
Then

when run it says type mismatch, but when i remove one,
eirther of them it's ok WHY????

i know i could put some code in befor and get wjhat i
want, but why is it a type mis match, i guess it has
somthinbg to do with the OR logical?

Any suggestions/solutiuons

at the mo i'll go with this long winder (i don't like IIF!)

IBC = 0
If Worksheets("1").Cells(acrow, 4).Value = "IBC" Then
IBC = 1
Else
IBC = 0
End If
If Worksheets("1").Cells(acrow, 4).Value = "IB2" Then
IBC = 1
Else
IBC = 0
End If

If IBC = 1 Then

THANKS Ross
 
D

Dave Peterson

Try something like:

if worksheets("1").cells(acrow,4).value = "IB2" _
or worksheets("1").cells(acrow,4).value = "IBC" then
or
with worksheets("1").cells(acrow,4)
if .value = "IB2" _
or .value = "IBC" then
'....
end with

And when the Or's get too much, try taking a look at Select Case:

Select Case Worksheets("1").Cells(acrow, 4).Value
Case Is = "IB2", "IBC"
'do your stuff
Case Is = "xyz", "somethingelse"
'do different stuff
Case Else
'do even more stuff
End Select

===
And do you have a worksheet that's named 1? I was just wondering if you really
meant the left most worksheet (worksheet(1) (no quotes))
 

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

Top