#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default Select Case

Hi,
I am having some trouble with Select Case. I have a bunch of ifelse
statements that would be run faster as a select case, but i cant get
the syntax. I want something like:

Function range(incw) as string

Select Case incw
Case is 0
range="None"
Case is 0 And <=5 ' This is the part im having
trouble with
range="Moderate"
Case is 5
range="Extreme"
End Select
End Function

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 897
Default Select Case

Try this:

Function range(incw) As String


Select Case incw
Case 0
range = "None"
Case incw 0 And incw <= 5
range = "Moderate"
Case Is 5
range = "Extreme"
End Select
End Function


HTH,
JP

On Jan 22, 12:47*pm, wrote:
Hi,
I am having some trouble with Select Case. *I have a bunch of ifelse
statements that would be run faster as a select case, but i cant get
the syntax. *I want something like:

Function range(incw) as string

*Select Case incw
* * * Case is 0
* * * * * * * * range="None"
* * * Case is 0 And <=5 * * * * * ' This is the part im having
trouble with
* * * * * * * * range="Moderate"
* * * Case is 5
* * * * * * * * range="Extreme"
*End Select
*End Function

Thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Select Case

On 22 Jan., 18:47, wrote:
Hi,
I am having some trouble with Select Case. *I have a bunch of ifelse
statements that would be run faster as a select case, but i cant get
the syntax. *I want something like:

Function range(incw) as string

*Select Case incw
* * * Case is 0
* * * * * * * * range="None"
* * * Case is 0 And <=5 * * * * * ' This is the part im having
trouble with
* * * * * * * * range="Moderate"
* * * Case is 5
* * * * * * * * range="Extreme"
*End Select
*End Function

Thanks


Hi


Function range(incw As Long) As String

Select Case incw
Case Is = 0
range = "None"
Case Is 5
range = "Extreme"
Case Else
range = "Moderate"
End Select
End Function

BTW: I wouldn't use range as function name as it also refers to an
object in VBA

Regards,

Per
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 897
Default Select Case

Tell me about it, I pasted the function into my VBE and it
(temporarily) broke all my macros! ;-)


--JP


On Jan 22, 12:59*pm, Per Jessen wrote:

BTW: I wouldn't use range as function name as it also refers to an
object in VBA

Regards,

Per

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Select Case

Select Case incw
Case is 5:s="Extreme"
Case is 0:s="M"
case else:x="N"
end select
mr=x

range="Extreme


Case is 0
range="None"
Case is 0 And <=5 ' This is the part im having
trouble with
range="Moderate"
Case is 5
range="Extreme"
End Select



--
Don Guillett
Microsoft MVP Excel
SalesAid Software

wrote in message
...
Hi,
I am having some trouble with Select Case. I have a bunch of ifelse
statements that would be run faster as a select case, but i cant get
the syntax. I want something like:

Function range(incw) as string

Select Case incw
Case is 0
range="None"
Case is 0 And <=5 ' This is the part im having
trouble with
range="Moderate"
Case is 5
range="Extreme"
End Select
End Function

Thanks




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default Select Case

On Jan 22, 1:43 pm, "Don Guillett" wrote:
Select Case incw
Case is 5:s="Extreme"
Case is 0:s="M"
case else:x="N"
end select
mr=x

range="Extreme
Case is 0
range="None"
Case is 0 And <=5 ' This is the part im having
trouble with
range="Moderate"
Case is 5
range="Extreme"
End Select


--
Don Guillett
Microsoft MVP Excel
SalesAid Software
wrote in message

...

Hi,
I am having some trouble with Select Case. I have a bunch of ifelse
statements that would be run faster as a select case, but i cant get
the syntax. I want something like:


Function range(incw) as string


Select Case incw
Case is 0
range="None"
Case is 0 And <=5 ' This is the part im having
trouble with
range="Moderate"
Case is 5
range="Extreme"
End Select
End Function


Thanks


ha ha sorry about the range object name, thats not actually the name
of my function nor is the code what my function does, its just a
simplified version. I will Try JP's suggestion again but i think i
tried it earlier and it did not work, didnt really understand Don's
coding, is that VBA?
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 897
Default Select Case

Yes, he just grouped the "Case" statements on one line. You can do
that by using ":"


HTH,
JP


On Jan 22, 2:02*pm, wrote:
On Jan 22, 1:43 pm, "Don Guillett" wrote:





Select Case incw
Case is 5:s="Extreme"
Case is 0:s="M"
case else:x="N"
end select
mr=x


ha ha sorry about the range object name, thats not actually the name
of my function nor is the code what my function does, its just a
simplified version. *I will Try JP's suggestion again but i think i
tried it earlier and it did not work, didnt really understand Don's
coding, is that VBA?

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Select Case

Correction and clarifications

Sub docase()
If Not IsNumeric(ActiveCell) Then Exit Sub
Select Case ActiveCell
Case Is 5: s = "Extreme"
Case Is 0: s = "M"
Case Else: s = "N"
End Select
mr = s
MsgBox mr
End Sub

Function mc(c)'c in the cell such as a1
If IsNumeric(c) Then
Select Case c
Case Is 5: s = "Extreme"
Case Is 0: s = "M"
Case Else: s = "N"
End Select
mc = s
End If
End Function


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Don Guillett" wrote in message
...
Select Case incw
Case is 5:s="Extreme"
Case is 0:s="M"
case else:x="N"
end select
mr=x

range="Extreme


Case is 0
range="None"
Case is 0 And <=5 ' This is the part im having
trouble with
range="Moderate"
Case is 5
range="Extreme"
End Select



--
Don Guillett
Microsoft MVP Excel
SalesAid Software

wrote in message
...
Hi,
I am having some trouble with Select Case. I have a bunch of ifelse
statements that would be run faster as a select case, but i cant get
the syntax. I want something like:

Function range(incw) as string

Select Case incw
Case is 0
range="None"
Case is 0 And <=5 ' This is the part im having
trouble with
range="Moderate"
Case is 5
range="Extreme"
End Select
End Function

Thanks



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
Case without Select Case error problem Ayo Excel Discussion (Misc queries) 2 May 16th 08 03:48 PM
End Select without Select Case, Block If without End If errors Atreides Excel Programming 12 November 17th 06 05:10 PM
Case Select Jimbola Excel Programming 11 December 11th 05 06:45 PM
Select Case Susan Hayes Excel Programming 1 November 4th 04 08:37 PM


All times are GMT +1. The time now is 08:10 PM.

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

About Us

"It's about Microsoft Excel"