1

I got another Problem with VBA. I used the TexttoColumns Sub to separate every Cell in my Column by semicolon. Now I wanted to insert Columns after that one, which should contain the separated values. It all worked pretty well in the beginning, but now it suddenly won't insert new cells, but overwrite the old ones.

Example (Wish) :

Row1           Row2   Row3   
Tree;PC;House |Data1 |Data2 -->  Tree|PC|House|Data1|Data2

Example(How it is):

Tree;PC;House|Data1|Data2 --> Tree|PC|House

Workbooks(Ziel).Worksheets(Zieltab).Columns(Spalte).TextToColumns Destination:=Columns(Spalte), DataType:=xlDelimited, _
    TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
    Semicolon:=True, Comma:=False, Space:=False, Other:=False, FieldInfo _
    :=Array(Array(1, 2), Array(2, 2))
2
  • as far is i know it, it will allways overwrite.. you may use =A1&";"&B1&";"&C1... after the last column and drag it down... copying it (value only) to the first column... then again use TextToColumns Commented Nov 6, 2015 at 9:42
  • wenn du verstehst was ich meine:D Commented Nov 6, 2015 at 9:43

1 Answer 1

2

A Range.TextToColumns method does not insert columns. It will always overwrite data if allowed to proceed.

With Workbooks(Ziel).Worksheets(Zieltab).Columns(Spalte)
    'insert two columns to the right
    .Cells(1).Resize(1, 2).Offset(0, 1).EntireColumn.Insert
    'split the first column into itself and the two new column
    .TextToColumns Destination:=.Cells(1), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
        Semicolon:=True, Comma:=False, Space:=False, Other:=False, _
        FieldInfo:=Array(Array(1, 2), Array(2, 2), Array(3, 2))
End With
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.