Case Select

Azar

New Member
Joined
Jun 28, 2011
Messages
28
Hi-
I entered the code below to look for specific text in 1 of 2 cells.
If that text is found, I want excel to display a specific output in a different cell.
When i run this macro, nothing happens, no errors, but no results on the worksheet.
any ideas? what am i missing here?
this is my first attempt at using Case function.

thanks,
Sub Case_Curr_Pairs()

Select Case Range("D1", "F1").Text

Case "EUR"
Range("L2").Value = EURUSD
Case "CHF"
Range("L2").Text = "USDCHF"
Case "CAD"
Range("L2").Text = "USDCAD"
Case "GBP"
Range("L21").Text = "GBPUSD"
Case "AUD"
Range("L2").Text = "AUDUSD"
Case "JPY"
Range("L2").Text = "USDJPY"

End Select
 
Is L21 a typo?

Here's a different version of the same idea:

Code:
Sub Case_Curr_Pairs()
Dim c As String, n As String
c = UCase(IIf(Range("D1") = "", Range("F1"), Range("D1")))
Select Case c
    Case "EUR": n = "EURUSD"
    Case "CHF": n = "USDCHF"
    Case "CAD": n = "USDCAD"
    Case "GBP": n = "GBPUSD"
    Case "AUD": n = "AUDUSD"
    Case "JPY": n = "USDJPY"
End Select
If n <> "" Then Range("L2") = n
End Sub
 
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Here is another way:

Code:
Sub Case_Curr_Pairs()
Dim c As String
c = UCase(IIf(Range("D1") = "", Range("F1"), Range("D1")))
Range("L2") = Switch( _
    c = "EUR", "EURUSD", _
    c = "CHF", "USDCHF", _
    c = "CAD", "USDCAD", _
    c = "GBP", "GBPUSD", _
    c = "AUD", "AUDUSD", _
    c = "JPY", "USDJPY")
End Sub

This could also just be done with a VLOOKUP formula on the spreadsheet.
 
Upvote 0
thanks for clarifying.
so is there another way to execute a function like this?
i'm working with data sets that require these sort of equations and was hoping there was a better way to do it than long winded IF AND statements...

thanks.
a
 
Upvote 0
Why don't you just use a VLOOKUP formula in the spreadsheet?

Excel Workbook
ABCDEFGHI
1EUREURUSDEUREURUSD
2CHFUSDCHF
3CADUSDCAD
4GBPGBPUSD
5AUDAUDUSD
6JPYUSDJPY
Sheet2
 
Upvote 0
thanks again for the help!

is there a way for an IF statement, in excel, (not vba) to return/output multiple results.
so =IF(C2="USD", D2="BUY", And E3="Curr", and F4="Trade"
would something like that work.

I would try it in vba, but i cant seem to get IF statements to work for me there.

thanks
 
Upvote 0

Forum statistics

Threads
1,224,506
Messages
6,179,158
Members
452,892
Latest member
yadavagiri

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top