Break up Date and Time in Cell

Guzzlr

Well-known Member
Joined
Apr 20, 2009
Messages
966
Office Version
  1. 2016
Platform
  1. Windows
Hello All,
I have a CSV file that prints out Date and Time in one cell: 1/4/2021 5:39 in column A
What I've been struggling with, is to break apart the Date and Time, and keep the Date in Column A, but place the Time in Column B.
I've not had any luck at this, can someone guide me please.
Thanks for the help
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
What about Text to Columns using Space as a delimiter.
 
Upvote 0
What about Text to Columns using Space as a delimiter.
Text to columns would work, but I was looking for VBA Code to include in the code there.
Is there a way to have this done in VBA?
thanks for the help
 
Upvote 0
Text to columns would work, but I was looking for VBA Code to include in the code there.
Is there a way to have this done in VBA?
Turn on your Macro Recorder, and record yourself performing the Text to Columns on this column, and you will have the VBA code that you need.
 
Upvote 0
that's what I did...sure seems messy though
Thanks for the help
 
Upvote 0
that's what I did...sure seems messy though
What's messy about it?
If you want the code cleaned up a bit, post what you recorded here, and we can help you simplify it.
 
Upvote 0
Something like this.
You'll need to play around with ranges to make it right for you.

VBA Code:
Sub Macro1()
    Selection.TextToColumns _
    Destination:=Range("A1"), _
    DataType:=xlDelimited, _
    ConsecutiveDelimiter:=True, _
    Space:=True
End Sub
 
Upvote 0
Solution
Something like this.
You'll need to play around with ranges to make it right for you.

VBA Code:
Sub Macro1()
    Selection.TextToColumns _
    Destination:=Range("A1"), _
    DataType:=xlDelimited, _
    ConsecutiveDelimiter:=True, _
    Space:=True
End Sub
This worked well, thanks!
 
Upvote 0
The suggestion leaves the date as Text in the first column and the time in the second column.

Is it possible to make the original column Date+Time and format it in an Internationally recognized format say yyyymmdd hh:mm?

If extra columns are required, could they to the right of existing data?
 
Upvote 0
The suggestion leaves the date as Text in the first column and the time in the second column.
It doesn't for me, and you can explicitly tell it to be a date if you want, i.e.
Rich (BB code):
Sub Macro1()
    Selection.TextToColumns _
    Destination:=Range("A1"), _
    DataType:=xlDelimited, _
    ConsecutiveDelimiter:=True, _
    Space:=True, _
    FieldInfo:=Array(Array(1, 3), Array(2, 3))
End Sub
I am guessing maybe it is different behaviors between US and European versions, as they sometimes handle dates a little differently.
 
Upvote 0

Forum statistics

Threads
1,215,757
Messages
6,126,693
Members
449,331
Latest member
smckenzie2016

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