excelvbatext-to-column

How can I create a macro to perform a TextToColumn on the column I'm currently selecting, Destination must be same Column


I want to create a macro that performs the TextToColumns on the current selection and place destination on the same column.

I tried the code below, but it doesn't work. What would be the correct way to set the column as a variable for the column I'm currently selecting when activating the macro?

    Sub Macro4()
'
' Macro4 Macro
'
' Atalho do teclado: Ctrl+t
'
    Selection.TextToColumns Destination:=Range("Selection"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
        :=Array(1, 2), TrailingMinusNumbers:=True
End Sub

Solution

  • This is a good time to use the record macro feature with "Use Relative References" selected. When I did this, Destination:=Range("Selection") in your code was changed to Destination:=ActiveCell.