Solved

# Select case and OR statement

Posted on 2002-03-23
Medium Priority
145 Views
Hi everyone,

while stepping through code in excel i saw this

-somevalue has the value of 36.8
-in the debugger
-?Range("J" & iRow - 4) gave 0
-?Range("L" & iRow - 4) gave 36.8

so you would expect this statement to be true and teh code go into dosomething

select case somevalue
case is = Range("J" & iRow - 4) Or Range("L" & iRow - 4)
dosomething
'......more comes here
end select

-the following worked as expected

select case somevalue
case is = Range("J" & iRow - 4)
dosomething
case is = Range("L" & iRow - 4)
'......more comes here
end select

-in the debugger the statement Range("J" & iRow - 4) Or Range("L" & iRow - 4) gave 37!

am i missing something here, it's not a real problem only a question maybe i'm doing something wrong in using the OR statement in the case select

:O)Bruintje
0
Question by:bruintje
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2
• 2
• 2

LVL 44

Author Comment

ID: 6891405
replaced the line with

Case Is = Range("J" & iRow - 4): Case Is = Range("L" & iRow - 4)

which worked ok but i still want to know about the case select and the OR
0

LVL 3

Accepted Solution

Bahnass earned 204 total points
ID: 6891431
I think
case Range("J" & iRow - 4) , Range("L" & iRow - 4)

in VB we say

SELECT CASE VARA
CASE A,B
' means vara = a or vara=b
dosomething
case c

case is > C

Case ELSE

end select

0

LVL 12

Expert Comment

ID: 6891432
I think that the .Value tries to read an integer value.
Try reading it as a string ?
0

LVL 44

Author Comment

ID: 6891439
that did it!

thanks a lot learned something new because in VB i did the same thing Case Is = but Case X,Y seems logical

:O)Bruintje
0

LVL 3

Expert Comment

ID: 6891582
0

LVL 12

Expert Comment

ID: 6892002
LOL - Overread that one..... ;-)
Great catch Bahnass!

D'Mzzl!
RoverM
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
###### Suggested Courses
Course of the Month10 days, 21 hours left to enroll