About Excel custom TEXTJOIN function, SWITCH function

table of Contents:

TEXTJOIN function introduction

SWITCH function introduction

Custom function method

Source


TEXTJOIN function:

TEXTJOIN function in Excel 2016 is the launch of a new version of the function.

The cell values ​​it is assembled into a region character string with a symbol.

such as:

There are "Long time no see" and "Are you okay" two cells, to connect them with a comma composed of a word, you can do this:

 

Syntax TEXTJOIN function: = TEXTJOIN (connector, whether to ignore the null value, the object to be merged)

 


SWITCH function:

Learned programming should be no stranger, which is similar to a multi-layer nested IF function, but with it, it is very efficient.

FIG usage examples:

 

SWITCH function Syntax: = SWITCH (target of judgment, the value of 1, a result, the value of 2, the results 2, .........)

SWITCH function can add up to a value of 126 for matching


Read the above, you must think of these two functions is very convenient, right?

but:

TEXTJOIN function in Excel2016 365 and above only, means that most users can not use this function, you have to use if you need to install 2,016,365 or later.

SWITCH function is a function of TEXTJOIN and released together, also need to use 365 or later.

 

But why not write a similar function?

I find the Internet a long time, patchwork, I found a similar code, but their official function and there are some differences, I modified a bit, making them basic and official functions exactly the same. In this way, we can use these functions in earlier versions of Excel.


Custom Function Method:

1. Download function package ( CSDN resources   or   Baidu network disk extraction code: Love )

2, to obtain the file as shown:

3, double click to open, it will be time to start Excel, it will prompt a warning:

4, this time need to click Enable Macros (enable macros to run custom function)

5. After you enable the macro, it opens the file. But it looks like nothing, because this is an add-in file. Try pressing Alt + F11 keys to open the VB editor, you can see the source of these two functions. Figure:

6, close the interface

7, now need to add this file to the startup items so that every time you open Excel will load these two functions

8, click on "File" => click on "Options" (You need to enable the "Developer Tools"):

9, enable the development tools:

10, the custom macro to add-ins:

 11, completed, then you can already use these two functions of:


It is worth noting : After the startup items to add to the macro Excel will copy a file to "C: \ Users \ username \ AppData \ Roaming \ Microsoft \ AddIns " inside, then you can download the file deleted, It does not affect use.

 


Source:

TEXTJOIN function:

' 自定义TEXTJOIN函数
Function TEXTJOIN(merger, ignore, ParamArray arr())
    Dim A As Variant, B As Variant, Mstr$
    If IsMissing(merger) Then merger = " "
    If Not IsMissing(arr) Then
        For Each A In arr
            If IsArray(A) Then
                For Each B In A
                    If ignore = 0 Or B <> "" Then Mstr = Mstr & merger & B
                Next
            Else
                If ignore = 0 Or A <> "" Then Mstr = Mstr & merger & A
            End If
        Next
    End If
    If Len(Mstr) Then TEXTJOIN = Mid(Mstr, 1 + Len(merger))
End Function

SWITCH function:

' 自定义SWITCH函数
Function SWITCH(Obj, ParamArray va())
    Application.Volatile True
    Dim i%
    For i = 0 To UBound(va) Step 2
        If va(i) = Obj Then
            SWITCH = va(i + 1)
            Exit Function
        End If
    Next
    SWITCH = False
End Function

 

Published 10 original articles · won praise 0 · Views 482

Guess you like

Origin blog.csdn.net/weixin_44549795/article/details/104850267