Using VBA to Perform Text To Columns, While Preserving Date and Time Formatting

reberryjr

Well-known Member
Joined
Mar 16, 2017
Messages
712
Office Version
  1. 365
Platform
  1. Windows
I need to take several fields with date/time formatting like this, and separate the time from the date. I've been formatting the column as MM/DD/YY HH:MM, which appears fine, but the value in the formula bar doesn't change. So, when I do text to columns, suing SPACE as the delimiter, I lose the 24 hour aspect. I even try to reformat the new Time column as HH:MM, but it doesn't hold.


Thoughts?
Incoming DataWhat I Want
6/13/2018 3:52 PM06/13/1815:52

<tbody>
</tbody>
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Nevermind. I was able to piece it together.
Code:
'Performs Text to Columns, separating the Date from the Time, and formats the Date as MM/DD/YY.
With sws.Range("D2:D" & slR)
    .TextToColumns Destination:=sws.Range("D2"), _
    DataType:=xlFixedWidth, _
    FieldInfo:=Array(Array(0, 3), Array(10, 1)), TrailingMinusNumbers:=True
    .NumberFormat = "mm/dd/yy;@"
End With
'Formats the Time as 24 Hour.
With sws.Range("E2:E" & slR)
    .NumberFormat = "hh:mm"
End With
 
Upvote 0

Forum statistics

Threads
1,221,476
Messages
6,160,062
Members
451,615
Latest member
soroosh

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