freelensia
New Member
- Joined
- Jul 2, 2017
- Messages
- 18
Hi,
Excel 2016 rolled out many new functions such as SWITCH, TEXTJOIN, etc. Unfortunately, these functions are not available for non-365 subscribers.
I was wondering if somebody built a VBA UDF for SWITCH already? Its syntax is the following:
[FONT=wf_segoe-ui_normal]Syntax[/FONT]
[FONT=wf_segoe-ui_normal]SWITCH(expression, value1, result1, [default or value2, result2],…[default or value3, result3])[/FONT]
[TABLE="class: banded flipColors, width: 673"]
<thead style="box-sizing: border-box;">[TR="bgcolor: #DADADA"]
[TD][FONT=wf_segoe-ui_semibold][FONT=wf_segoe-ui_normal]Argument[/FONT][/FONT]
[/TD]
[TD][FONT=wf_segoe-ui_semibold][FONT=wf_segoe-ui_normal]Description[/FONT][/FONT]
[/TD]
[/TR]
</thead><tbody style="box-sizing: border-box;">[TR="bgcolor: #F4F4F4"]
[TD][FONT=wf_segoe-ui_normal]expression
(required)[/FONT]
[/TD]
[TD][FONT=wf_segoe-ui_normal]Expression is the value (such as a number, date or some text) that will be compared against value1…value126.[/FONT]
[/TD]
[/TR]
[TR]
[TD][FONT=wf_segoe-ui_normal]value1…value126
[/FONT]
[/TD]
[TD][FONT=wf_segoe-ui_normal]ValueN is a value that will be compared against expression.[/FONT]
[/TD]
[/TR]
[TR="bgcolor: #F4F4F4"]
[TD][FONT=wf_segoe-ui_normal]result1…result126
[/FONT]
[/TD]
[TD][FONT=wf_segoe-ui_normal]ResultN is the value to be returned when the corresponding valueN argument matches expression. ResultN and must be supplied for each corresponding valueN argument.[/FONT]
[/TD]
[/TR]
[TR]
[TD][FONT=wf_segoe-ui_normal]default
(optional)[/FONT]
[/TD]
[TD][FONT=wf_segoe-ui_normal]Default is the value to return in case no matches are found in the valueN expressions. The Default argument is identified by having no corresponding resultN expression (see examples). Default must be the final argument in the function.[/FONT]
[/TD]
[/TR]
</tbody>[/TABLE]
[FONT=wf_segoe-ui_normal]Because functions are limited to 254 arguments, you can use up to 126 pairs of value and result arguments.[/FONT]
I imagine you would use Case select. However the problem is how the recognize the last input variable as the default output and return it in the right scenario.
Anybody has some sample (incomplete is fine) that could get me started?
Thanks!
Excel 2016 rolled out many new functions such as SWITCH, TEXTJOIN, etc. Unfortunately, these functions are not available for non-365 subscribers.
I was wondering if somebody built a VBA UDF for SWITCH already? Its syntax is the following:
[FONT=wf_segoe-ui_normal]Syntax[/FONT]
[FONT=wf_segoe-ui_normal]SWITCH(expression, value1, result1, [default or value2, result2],…[default or value3, result3])[/FONT]
[TABLE="class: banded flipColors, width: 673"]
<thead style="box-sizing: border-box;">[TR="bgcolor: #DADADA"]
[TD][FONT=wf_segoe-ui_semibold][FONT=wf_segoe-ui_normal]Argument[/FONT][/FONT]
[/TD]
[TD][FONT=wf_segoe-ui_semibold][FONT=wf_segoe-ui_normal]Description[/FONT][/FONT]
[/TD]
[/TR]
</thead><tbody style="box-sizing: border-box;">[TR="bgcolor: #F4F4F4"]
[TD][FONT=wf_segoe-ui_normal]expression
(required)[/FONT]
[/TD]
[TD][FONT=wf_segoe-ui_normal]Expression is the value (such as a number, date or some text) that will be compared against value1…value126.[/FONT]
[/TD]
[/TR]
[TR]
[TD][FONT=wf_segoe-ui_normal]value1…value126
[/FONT]
[/TD]
[TD][FONT=wf_segoe-ui_normal]ValueN is a value that will be compared against expression.[/FONT]
[/TD]
[/TR]
[TR="bgcolor: #F4F4F4"]
[TD][FONT=wf_segoe-ui_normal]result1…result126
[/FONT]
[/TD]
[TD][FONT=wf_segoe-ui_normal]ResultN is the value to be returned when the corresponding valueN argument matches expression. ResultN and must be supplied for each corresponding valueN argument.[/FONT]
[/TD]
[/TR]
[TR]
[TD][FONT=wf_segoe-ui_normal]default
(optional)[/FONT]
[/TD]
[TD][FONT=wf_segoe-ui_normal]Default is the value to return in case no matches are found in the valueN expressions. The Default argument is identified by having no corresponding resultN expression (see examples). Default must be the final argument in the function.[/FONT]
[/TD]
[/TR]
</tbody>[/TABLE]
[FONT=wf_segoe-ui_normal]Because functions are limited to 254 arguments, you can use up to 126 pairs of value and result arguments.[/FONT]
I imagine you would use Case select. However the problem is how the recognize the last input variable as the default output and return it in the right scenario.
Anybody has some sample (incomplete is fine) that could get me started?
Thanks!