• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Excel macro question

sundev

Golden Member
Just a quick question for any Excel macro/VBA gurus, why is the following line generating a "Type Mismatch" error?

If (Range("B3").Value = "AAA111" Or "AAA112" Or "AAA113") Then

As usual any help is appreciated.
 
I haven't used VBA for much, but is there and If...Or conditional?

I only know of:
  • IF...Then
  • If...Else
  • If...Then...elseif
  • Select Case

A conditional "OR" is available as a worksheet function, but I can't recall if it's accessible from VBA (there are a limited number of worksheet functions available from VBA)
 
Not tested, but I'm pretty sure that you need:

If (Range("B3").Value = "AAA111" Or Range("B3").Value = "AAA112" Or Range("B3").Value = "AAA113") Then

You should also be able to do this:

With Range("B3")
If (.Value = "AAA111" Or .Value = "AAA112" Or .Value = "AAA113") Then

Do that thing that you do

End if
End With
 
Thanks for the help Mayest, you were right. I used the "With" method to clean it up a little bit too.

Thanks again
 
Back
Top