Solved

Select case and OR statement

Posted on 2002-03-23
6
133 Views
Last Modified: 2010-05-02
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
Comment
Question by:bruintje
  • 2
  • 2
  • 2
6 Comments
 
LVL 44

Author Comment

by:bruintje
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

by:
Bahnass earned 51 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

by:roverm
ID: 6891432
I think that the .Value tries to read an integer value.
Try reading it as a string ?
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 44

Author Comment

by:bruintje
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

by:Bahnass
ID: 6891582
thanks 4 points & Grade
0
 
LVL 12

Expert Comment

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

D'Mzzl!
RoverM
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now