excelvbadate-formattingtext-to-column

I want to eliminate exact range (G1) & make this Text to column code dynamic to convert column values to date


    ActiveCell.EntireColumn.Select
    Selection.TextToColumns Destination:=Range("G1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
        :=Array(1, 4), TrailingMinusNumbers:=True
    Selection.NumberFormat = "dd-mmm-yy"

Solution

  • I found the solution , Thanks for support , Modified code should be

    ActiveCell.EntireColumn.Select
    
    Dim myRange As Range
    Set myRange = Selection
    
    myRange.TextToColumns Destination:=myRange, DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
        :=Array(1, 4), TrailingMinusNumbers:=True
    Selection.NumberFormat = "dd-mmm-yy"