AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
1,835
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
I'm having bit of brainfade, I think !

Private p As String
Private d As String
Private m As String
The value I want to assign is returned by Designations("m/") or "p/" etc.

Code:
Function Designations(d As String) As Variant
    Designations = Switch(d = "p/", "Producer:", d = "o/", "Orchestra:", d = "m/", "Movie Or Musical:")
End Function

Do I need for example, m= Designations("m/"), repeated for every case, or can I somehow handle it with one line regardless of value "m/" or "d/" or "p/"
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
The Switch function is not a very efficient function. How about something like this...
Code:
[table="width: 500"]
[tr]
	[td]Function Designations(d As String) As Variant
  Dim Arr As Variant
  Arr = Array("p/Producer:", "o/Orchestra:", "m/Movie Or Musical:")
  Designations = Mid(Filter(Arr, d, True, vbTextCompare)(0), 3)
End Function[/td]
[/tr]
[/table]
While harder to read, you can make the above a one-liner (if that is what the intent behind your posted code was trying to project that you wanted)...
Code:
[table="width: 500"]
[tr]
	[td]Function Designations(d As String) As Variant
  Designations = Mid(Filter(Array("p/Producer:", "o/Orchestra:", "m/Movie Or Musical:"), d, True, vbTextCompare)(0), 3)
End Function[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0
Thanks Rick, I've binned all the switch stuff and changed to what you suggested.
Cheers, Alex
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

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