Right align dates

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,913
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
The problem I have is exactly as described in this article:

Rich (BB code):
https://www.excelforum.com/excel-general/702292-alignment-of-dates.html



What seems to be a date is actually text, so correct it, the suggestion was to use the Text To Columns function.

It worked manually, so I recorded my steps to see the code:

Rich (BB code):
 Columns("P:P").Select
    Selection.TextToColumns Destination:=Range("P1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
        :=Array(1, 1), TrailingMinusNumbers:=True



However, when I ran the code, the heading moved up from row 7 to 6.

Can someone please tell me what's wrong.

Thanks

<strike>
</strike>
 
Last edited:

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
This seemed to do the trick:

Rich (BB code):
https://stackoverflow.com/questions/28516923/excel-date-formatting-not-working



with this code:

Rich (BB code):
Sub mdy_2_dmy_by_Sel() Dim rDT As Range With Selection .Replace what:=Chr(160), replacement:=Chr(32), lookat:=xlPart .TextToColumns Destination:=.Cells(1, 1), DataType:=xlFixedWidth, FieldInfo:=Array(0, 1) For Each rDT In .Cells Application.EnableEvents = False rDT = CDate(rDT.Value2) Application.EnableEvents = True Next rDT .NumberFormat = "dd/mm/yyyy" End With End Sub​


<strike>
</strike>
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,988
Members
452,373
Latest member
TimReeks

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