Test to column not working.

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,059
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
I am not sure this is a recorded code and if I try to execute it its not working, not sure why. It has no effect on the cells. I am trying to convert date from 17/06/22 to 17-06-2022

VBA Code:
Sub Macro3()
'
' Macro3 Macro
'

    Range("E9").Select
    Range(Selection, Selection.End(xlDown)).Select
    Application.CutCopyMode = False
    Selection.TextToColumns Destination:=Range("$E$9:$E$32"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
        :=Array(1, 1), TrailingMinusNumbers:=True
    Range("E56").Select
    Selection.End(xlUp).Select
End Sub
 

Attachments

  • CopyPaste Date.jpg
    CopyPaste Date.jpg
    106.7 KB · Views: 10

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
What happens with the code below?

VBA Code:
Sub vmjan02()

   Range("E9:E32").TextToColumns Destination:=Range("E9"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
        :=Array(1, 4), TrailingMinusNumbers:=False
   Range("E9:E32").NumberFormat = "dd-mm-yyyy"
End Sub
 
Last edited:
Upvote 0
Solution
Thanks Mark this is working fine and perfect, thanks and guiding me out.
 
Upvote 0
You're welcome

Just for your reference your issue was FieldInfo:=Array(1, 1), the first 1 is fine as it is a reference to the column. The range is a single column so it can only be 1.
The issue is the 2nd 1. This is the Datatype. When you are doing a conversion you need to match what you see in the cell, in this case it is a date in dd/mm/yyyy format.
The 1 you were using is the General format datatype (xlGeneralFormat) whereas I used FieldInfo:=Array(1, 4), the 4 is the datatype to use for dd/mm/yyyy format (xlDMYFormat)
 
Upvote 0

Forum statistics

Threads
1,215,071
Messages
6,122,964
Members
449,094
Latest member
Anshu121

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top