Wauvel

Excel like a finance pro.

← All VBA snippets

Split one column into several

The memo field that arrives as "Acme | INV-1042 | 2026-08-31", taken apart in code.

1What it does

Bank and system exports love to pack several facts into one field. `TextToColumns` splits it on a delimiter into as many columns as there are pieces. Two things make it safe in a macro. It overwrites whatever is to the right without asking, so insert blank columns first. And it needs to be told what each output column is — left to its defaults, it reads a date in whatever order the machine's locale prefers, and reads a code like 00123 as the number 123, losing the leading zeros that make it a code.

2The code

Sub SplitMemoColumn()
    Dim ws As Worksheet, lastRow As Long
    Set ws = ActiveSheet
    lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
    If lastRow < 2 Then Exit Sub

    ' Make room first — TextToColumns overwrites to the right without asking.
    ws.Columns("B:C").Insert Shift:=xlToRight

    ws.Range("A2:A" & lastRow).TextToColumns _
        Destination:=ws.Range("A2"), _
        DataType:=xlDelimited, _
        ConsecutiveDelimiter:=False, _
        Other:=True, OtherChar:="|", _
        FieldInfo:=Array( _
            Array(1, xlGeneralFormat), _
            Array(2, xlTextFormat), _
            Array(3, xlYMDFormat)), _
        TrailingMinusNumbers:=True

    ' The pieces keep their surrounding spaces; strip them.
    Dim c As Range
    For Each c In ws.Range("A2:C" & lastRow)
        c.Value = Trim$(c.Value)
    Next c

    ws.Range("A1:C1").Value = Array("Customer", "Invoice", "Date")
End Sub

Paste into the Visual Basic Editor (Alt + F11 → Insert → Module), then run and save as macro-enabled (.xlsm).

New to macros? Set up in 5 minutes
  1. 1

    Don't see the Developer tab in the ribbon?

    You don't strictly need it — Alt + F11 opens the editor directly — but it makes running macros easier.
    • Windows: File → Options → Customize Ribbon → tick Developer in the right-hand list → OK.
    • Mac: Excel → Preferences → Ribbon & Toolbar → tick Developer → Save.
  2. 2

    Paste in the code

    Press Alt + F11 to open the Visual Basic editor, then Insert → Module and paste the snippet's code into the blank window. Close it with Alt + Q.
  3. 3

    Run it

    Press Alt + F8, pick the macro's name, and click Run — that's it. (Pasted a custom function instead? Just type it into a cell like any built-in: =GrossMargin(B2, B3).)
  4. 4

    Keep the macro — save as .xlsm

    File → Save As → Excel Macro-Enabled Workbook (.xlsm). A plain .xlsx silently drops the code when you save.
  5. 5

    Macros blocked?

    Click Enable Content on the yellow bar. If you downloaded the file, you may first need to right-click it → Properties → tick Unblock → OK, then reopen.

Heads up: macros can't be undone with Ctrl + Z — save a copy before running one that changes your workbook.

3When you use it

  • Split a combined reference into customer, invoice and date.
  • Separate an account code from its description.
  • Take apart a bank memo line before matching it to invoices.

4See it in action

A simulation — press Run to perform what the macro does to a sample workbook.

AB
Acme | INV-1042 | 2026-08-314,200

One field doing three jobs, with the amount sitting right next to it.

5Pitfalls

It overwrote the columns to the right, with no warning and no undo once the macro has run.

Fix: Insert the blank columns first, as above.

Dates came out with day and month swapped.

Fix: Tell it the order with FieldInfo — xlYMDFormat, xlDMYFormat — rather than trusting the locale.

A code like 00123 became the number 123.

Fix: xlTextFormat for that column in FieldInfo keeps it text, zeros intact.

Pieces carry their spaces, so "Acme " won't match "Acme".

Fix: Trim each cell after the split.

6No-code alternatives

  • Data → Text to Columns The same wizard by hand. See the tip — including its second use for fixing text numbers.
  • TEXTSPLIT Splits into a spilled formula result and leaves the source alone, which is safer when the data keeps arriving.

Rather not write macros? Wauvel's free tools generate branded, formula-driven Excel for you — no VBA required.

Learn the moves here — or let Wauvel run them on your numbers.

Meet your AI CFO →

One CFO-grade Excel tip a week

A short, practical email for finance operators — functions, shortcuts, and the moves that save an afternoon. Free, unsubscribe anytime.