0

I have an excel with some data separated by ";" in a cell. I need to split that cell, and some subsequent one, so that splitted content will go each to a new line each. Example:

Column f    Column j     Column k
a;b;c       d;e;f        g;h;i

Should become

a         d       g
b         e       h
c         f       i

This is what i have, but not working:

Sub tgr()

Dim rindex As Long
Dim saItem() As String
Dim sbItem() As String
Dim scItem() As String

For rindex = Cells(Rows.Count, "F").End(xlUp).Row To 1 Step -1
    If InStr(Cells(rindex, "F").Value, ";") > 0 Then
        saItem = Split(Cells(rindex, "F").Value, ";")
        sbItem = Split(Cells(rindex, "J").Value, ";")
        scItem = Split(Cells(rindex, "K").Value, ";")
        Rows(rindex + 1 & ":" & rindex + UBound(saItem)).Insert
        Cells(rindex, "F").Resize(UBound(saItem) + 1).Value = WorksheetFunction.Transpose(saItem)
        Cells(rindex, "J").Resize(UBound(sbItem) + 1).Value = WorksheetFunction.Transpose(sbItem)
        Cells(rindex, "K").Resize(UBound(scItem) + 1).Value = WorksheetFunction.Transpose(scItem)
    End If
Next rindex

End Sub

Thanks for your help

1
  • you code is working for me as expected. What is wrong in your opinion? Commented Nov 17, 2013 at 20:33

1 Answer 1

1

You are using the wrong array for Col K. I guess you copy pasted and forgot to change it? :)

Replace the line

Cells(rindex, "K").Resize(UBound(sbItem) + 1).Value = WorksheetFunction.Transpose(sbItem)

with

Cells(rindex, "K").Resize(UBound(scItem) + 1).Value = WorksheetFunction.Transpose(scItem)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.