Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Susan Hayes
 
Posts: n/a
Default Need help on Select Case

I am using a large number of ElseIf statements, and running into
problems. I was informed to use Select Case instead. However I am
not familiar with the Select Case syntax.

I have written below a small sample of my ElseIf statement, can
someone please write the equivalent in Select Case syntax.

Thank you in advance,

Susan




Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If [b6] = "United Kingdom" And [b62] = "USD" Then
[b16] = [r13]
[b17] = [a1] * [b1]
ElseIf [b6] = "United Kingdom" And [b62] = "CAD" Then
[b16] = [p13]
[b17] = [a2] * [b2]
ElseIf [b6] = "Hong Kong" And [b62] = "USD" Then
[b16] = [r2]
[b17] = [a6] * [b6]
ElseIf [b6] = "Hong Kong" And [b62] = "CAD" Then
[b16] = [p2]
[b17] = [a7] * [b7]
Else:
[b16] = ""
[b17] = ""
End If

End Sub


  #2   Report Post  
Don Guillett
 
Posts: n/a
Default

From help
Using Select Case Statements
Use the Select Case statement as an alternative to using ElseIf in
If...Then...Else statements when comparing one expression to several
different values. While If...Then...Else statements can evaluate a different
expression for each ElseIf statement, the Select Case statement evaluates an
expression only once, at the top of the control structure.

In the following example, the Select Case statement evaluates the
performance argument that is passed to the procedure. Note that each Case
statement can contain more than one value, a range of values, or a
combination of values and comparison operators. The optional Case Else
statement runs if the Select Case statement doesn't match a value in any of
the Case statements.

Function Bonus(performance, salary)
Select Case performance
Case 1
Bonus = salary * 0.1
Case 2, 3
Bonus = salary * 0.09
Case 4 To 6
Bonus = salary * 0.07
Case Is 8
Bonus = 100
Case Else
Bonus = 0
End Select
End Function

--
Don Guillett
SalesAid Software

"Susan Hayes" wrote in message
...
I am using a large number of ElseIf statements, and running into
problems. I was informed to use Select Case instead. However I am
not familiar with the Select Case syntax.

I have written below a small sample of my ElseIf statement, can
someone please write the equivalent in Select Case syntax.

Thank you in advance,

Susan




Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If [b6] = "United Kingdom" And [b62] = "USD" Then
[b16] = [r13]
[b17] = [a1] * [b1]
ElseIf [b6] = "United Kingdom" And [b62] = "CAD" Then
[b16] = [p13]
[b17] = [a2] * [b2]
ElseIf [b6] = "Hong Kong" And [b62] = "USD" Then
[b16] = [r2]
[b17] = [a6] * [b6]
ElseIf [b6] = "Hong Kong" And [b62] = "CAD" Then
[b16] = [p2]
[b17] = [a7] * [b7]
Else:
[b16] = ""
[b17] = ""
End If

End Sub




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
displaying ranges iart Excel Discussion (Misc queries) 15 September 10th 05 02:02 PM
Amount or Numbers in Words ron New Users to Excel 6 December 24th 04 07:32 PM
Identifying the Active Fill Color Steve Conary Excel Discussion (Misc queries) 3 December 9th 04 04:45 AM
change typed text to upper case CT Cameron Excel Discussion (Misc queries) 2 November 30th 04 01:07 AM
How do I change existing text from lower case to upper case CT Cameron Excel Discussion (Misc queries) 2 November 30th 04 01:07 AM


All times are GMT +1. The time now is 12:37 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"