Macro to split data and time into two columns

abberyfarm

Well-known Member
Joined
Aug 14, 2011
Messages
733
hi there,

I have dates and times in one column like this "12/08/2011 11:24", would anyone have a macro to split them into two columns?
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
I wasn't sure if yyou wanted it offset or in-place. Just to try on a junk copy of your wb, select the cells and run:

Rich (BB code):
Option Explicit
    
Sub SplitDateTime()
Dim Cell As Range
    
    For Each Cell In Selection
        If IsDate(Cell.Value) Then
            Cell.Offset(, 1).Resize(, 2).Value _
                = Array(DateSerial(Year(Cell.Value), Month(Cell.Value), Day(Cell.Value)), _
                        TimeSerial(Hour(Cell.Value), Minute(Cell.Value), Second(Cell.Value)))
        End If
    Next
End Sub

To get:

Excel Workbook
EFG
1BeforeAfterAfter
29/18/2011 13:249/18/201113:24
39/19/2011 14:009/19/201114:00
49/20/2011 7:009/20/201107:00
510/10/2010 23:5310/10/201023:53
Sheet4
 
Upvote 0

Forum statistics

Threads
1,224,520
Messages
6,179,267
Members
452,902
Latest member
Knuddeluff

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