Split words using VBA in Excel cells

Diddy

I would like to split a string with tokens separated ‘;’ into 2 list of values. For example I have the string: AXX1.CYY1;AXX2.CYY2;AXX3.CYY3;AXX4.CYY4 I would like list it to be separated into 2 lists, the first should contain values on the right of ‘.’ whereas the second should have values on the left Practically, the outcome should be:

AXX1;AXX2;AXX3;AXX4
CYY1;CYY2;CYY3;CYY4

So far I think my strategy is create a loop in a VBA function that splits the words. The single value is in turn split into 2 portions which are put in a list. Further to this how do you apply the code to excel cells. If there is any other method to accomplish it is welcome.

John Coleman

Your basic logic makes sense. It can be implemented like thus:

Function ChopandSplice(s As String) As Variant
    Dim chunks As Variant, first As Variant, second As Variant
    Dim temp As Variant
    Dim i As Long
    chunks = Split(s, ";")
    ReDim first(0 To UBound(chunks))
    ReDim second(0 To UBound(chunks))
    For i = 0 To UBound(chunks)
        temp = Split(chunks(i), ".")
        first(i) = temp(0)
        second(i) = temp(1)
    Next i
    ChopandSplice = Array(Join(first, ";"), Join(second, ";"))
End Function

Sub test()
    Dim v As Variant
    v = ChopandSplice("AXX1.CYY1;AXX2.CYY2;AXX3.CYY3;AXX4.CYY4")
    Range("A1") = v(0)
    Range("B1") = v(1)
End Sub

Running the test sub leads to:

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to split and restructure cells using excel VBA

From Dev

Split cells by uppercase and lowercase words in excel

From Dev

Split cells with formula in next row Excel vba

From Dev

Excel VBA to split cell into multiple cells

From Dev

Using Split function with Cells, Range, Rows.count, and xlup on excel-vba

From Dev

Split last two words in a sentence into two different cells in MS Excel

From Dev

Insert formula into cells using excel vba

From Dev

Excel VBA select range using cells and xlDown

From Dev

compare 2 cells in excel by using vba

From Dev

calculate count of certain cells using vba in excel

From Dev

Using AutoFill in Excel VBA for a range of cells

From Dev

Excel VBA - Split a cell into 1000 pieces and copy them into different cells

From Dev

Tagging Words Using VBA in MS Excel

From Dev

how to split cells like Jan to Aug As Jan,Feb, Mar, Apr, Jun,Jul, Aug like this in excel using vba

From Dev

MS Excel: How to insert words in cells using Find and Replace

From Dev

How to automatically split cells in word table using VBA

From Dev

excel vba Split funtion using " as delimiter

From Dev

How to split words in Excel

From Dev

Excel VBA- Split Cell Strings into individual cells and copy cells to new sheet

From Dev

Category name in excel charts, using VBA without using any Cells

From Dev

Split Cells by Line Break VBA

From Dev

VBA - How do I compare text in Excel cells to see if same words are found, exclusing punctuation?

From Dev

split cell on underlined words vba

From Dev

Loading VBA JSON variable then referencing it in Cells using Excel Formulas

From Dev

Clear the Excel cells format using VBA without clearing the NumberFormat

From Dev

Error on adding two cells using Excel-VBA for Mac

From Dev

VBA Excel: Copying across sheets using alphanumeric range vs cells

From Dev

How to do standard deviation on desired ranged of cells using Excel VBA?

From Dev

Excel 2007 using VBA write formula to merged cells

Related Related

  1. 1

    How to split and restructure cells using excel VBA

  2. 2

    Split cells by uppercase and lowercase words in excel

  3. 3

    Split cells with formula in next row Excel vba

  4. 4

    Excel VBA to split cell into multiple cells

  5. 5

    Using Split function with Cells, Range, Rows.count, and xlup on excel-vba

  6. 6

    Split last two words in a sentence into two different cells in MS Excel

  7. 7

    Insert formula into cells using excel vba

  8. 8

    Excel VBA select range using cells and xlDown

  9. 9

    compare 2 cells in excel by using vba

  10. 10

    calculate count of certain cells using vba in excel

  11. 11

    Using AutoFill in Excel VBA for a range of cells

  12. 12

    Excel VBA - Split a cell into 1000 pieces and copy them into different cells

  13. 13

    Tagging Words Using VBA in MS Excel

  14. 14

    how to split cells like Jan to Aug As Jan,Feb, Mar, Apr, Jun,Jul, Aug like this in excel using vba

  15. 15

    MS Excel: How to insert words in cells using Find and Replace

  16. 16

    How to automatically split cells in word table using VBA

  17. 17

    excel vba Split funtion using " as delimiter

  18. 18

    How to split words in Excel

  19. 19

    Excel VBA- Split Cell Strings into individual cells and copy cells to new sheet

  20. 20

    Category name in excel charts, using VBA without using any Cells

  21. 21

    Split Cells by Line Break VBA

  22. 22

    VBA - How do I compare text in Excel cells to see if same words are found, exclusing punctuation?

  23. 23

    split cell on underlined words vba

  24. 24

    Loading VBA JSON variable then referencing it in Cells using Excel Formulas

  25. 25

    Clear the Excel cells format using VBA without clearing the NumberFormat

  26. 26

    Error on adding two cells using Excel-VBA for Mac

  27. 27

    VBA Excel: Copying across sheets using alphanumeric range vs cells

  28. 28

    How to do standard deviation on desired ranged of cells using Excel VBA?

  29. 29

    Excel 2007 using VBA write formula to merged cells

HotTag

Archive