Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Passing a string to Case statement

My current code reads:


Select Case Cells(i, 8)
Case "ABC", "DEF", "GHI"
......
End select

Since I have different of these cases I wonder if it is possible to use a
variable as follows:


Dim CaseVariable as variant
Set CaseVariable= "ABC"
Select Case Cells(i, 8)
Case CaseVariable
......
End select

So far I cannot get this working. Is it possible? Please advise.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 112
Default Passing a string to Case statement

Hello Beertje
Declare your variable as String and may be constant as well:
Const CaseVariable As String = "ABC"
Select Case Cells(i,8)
Case CaseVariable
'....

HTH
Cordially
Pascal

"Beertje" a écrit dans le message de
news: ...
My current code reads:


Select Case Cells(i, 8)
Case "ABC", "DEF", "GHI"
......
End select

Since I have different of these cases I wonder if it is possible to use a
variable as follows:


Dim CaseVariable as variant
Set CaseVariable= "ABC"
Select Case Cells(i, 8)
Case CaseVariable
......
End select

So far I cannot get this working. Is it possible? Please advise.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Passing a string to Case statement

For 1 entry no problem but how to get this work for 2 or more like:
"ABC", "DEF", "GHI"

thx.

"papou" wrote:

Hello Beertje
Declare your variable as String and may be constant as well:
Const CaseVariable As String = "ABC"
Select Case Cells(i,8)
Case CaseVariable
'....

HTH
Cordially
Pascal

"Beertje" a écrit dans le message de
news: ...
My current code reads:


Select Case Cells(i, 8)
Case "ABC", "DEF", "GHI"
......
End select

Since I have different of these cases I wonder if it is possible to use a
variable as follows:


Dim CaseVariable as variant
Set CaseVariable= "ABC"
Select Case Cells(i, 8)
Case CaseVariable
......
End select

So far I cannot get this working. Is it possible? Please advise.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Passing a string to Case statement

Got it working.
thx
using
Case casevar(1), casevar(2), casevar(3), casevar(4)
works better, since I can then have also an empty string.

"papou" wrote:

Beertje
Dunno if this could be useful in your case but anyway:
Dim CaseVariable(0 To 2)
CaseVariable(0) = "ABC"
CaseVariable(1) = "DEF"
CaseVariable(2) = "GHI"
Select Case Cells(1, 8)
Case CaseVariable(0) To CaseVariable(2)
MsgBox "match found"
End Select

HTH
Cordially
Pascal

"Beertje" a écrit dans le message de
news: ...
For 1 entry no problem but how to get this work for 2 or more like:
"ABC", "DEF", "GHI"

thx.

"papou" wrote:

Hello Beertje
Declare your variable as String and may be constant as well:
Const CaseVariable As String = "ABC"
Select Case Cells(i,8)
Case CaseVariable
'....

HTH
Cordially
Pascal

"Beertje" a écrit dans le message de
news:
...
My current code reads:


Select Case Cells(i, 8)
Case "ABC", "DEF", "GHI"
......
End select

Since I have different of these cases I wonder if it is possible to use
a
variable as follows:


Dim CaseVariable as variant
Set CaseVariable= "ABC"
Select Case Cells(i, 8)
Case CaseVariable
......
End select

So far I cannot get this working. Is it possible? Please advise.






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing Query String into MS Excel napval Excel Discussion (Misc queries) 0 June 19th 07 06:04 AM
Passing String to Formula1 Method in VB Stew Excel Programming 1 February 1st 05 01:33 AM
Passing a String in Array to Range as String [email protected] Excel Programming 2 September 1st 04 01:13 AM
string passing to DLL Christoph Wirz Excel Programming 1 February 20th 04 02:40 PM
PASSING A STRING VALUE Sirron Excel Programming 2 August 26th 03 06:40 PM


All times are GMT +1. The time now is 01:11 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"