Пример макроса: Разделение строки с элементами через разделители, сборка строки

Исходный пример на VBA
Sub SplitJoinTesting()          '' e31 split
    Dim MyArray() As String, MyString As String, i As Variant, n As Integer
    Dim target As String
    
    'Sample string with ";" delimiters
    MyString = "One;Two;Three;Four;Five;Six"
    Range("A1").value = MyString
    'Use Split function to divide up the component parts of the string
    MyArray = Split(MyString, ";")
    'Use Join function to re-create the original string using a semi colon delimiter
    target = Join(MyArray, "   ")
    Range("A2").value = target
    
    ' Using the Split Function to do a Word Count
    Range("A3") = "Number of Words: " & UBound(MyArray) + 1
        
    'Splitting an Address into Worksheet Cells
    MyString = "Microsoft Corporation_One Microsoft Way_Redmond_WA 98052-6399 USA"
    MyArray = Split(MyString, "_")
    'iterate through the array
    For n = 0 To UBound(MyArray)
         'Place each split into the first column of the worksheet
        Range("A" & n + 6).value = MyArray(n)
    Next n
    
    'place each array element plus a line feed character into a string
    target = ""
    For n = 0 To UBound(MyArray)
        target = target & MyArray(n) & vbLf
    Next n
    Range("A12") = target
    
    Columns("A").AutoFit
End Sub
JavaScript Р7
(function() {
    var oSheet = Api.GetActiveSheet();
    
    // Sample string with ";" delimiters
    var myString = "One;Two;Three;Four;Five;Six";
    oSheet.GetRange("A1").SetValue(myString);
    // Use Split function to divide up the component parts of the string
    var myArray = myString.split(";")
    //Use Join function to re-create the original string using a semi colon delimiter
    var target = myArray.join("   ");
    oSheet.GetRange("A2").SetValue(target);

    // Using the Split Function to do a Word Count
    oSheet.GetRange("A3").SetValue("Number of Words:  " + myArray.length);

    // Splitting an Address into Worksheet Cells
    myString = "Microsoft Corporation_One Microsoft Way_Redmond_WA 98052-6399 USA";
    myArray = myString.split("_");
    // iterate through the array
    var n = 6;
    myArray.forEach((item) => {
        oSheet.GetRange("A" + n++).SetValue(item);
    })
    
    // place each array element plus a line feed character into a string
    target = ""
    myArray.forEach((item) => {
        target += item + "\n";
    })
    oSheet.GetRange("A12").SetValue(target);
    oSheet.GetRange("A12").SetWrap(true);
    
    oSheet.GetCols("A").AutoFit(false,true);    
})();
Поддержка слушателей курса
"Основы Java Script для Р7"