Macro code help

markster

Well-known Member
Joined
May 23, 2002
Messages
579
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hello all,
I just need a bit of macro code that will look down data in column B (from B2 onwards) which is in this format 2020.03.11 13:32 and add 11-Mar-20 into column C and 13:32 into column D so I can sort by date and time.

So in this case

Column B will show. 2020.03.11 13:32
Column C will Show 11-Mar-20
Column D will show 13:32

Thanks,
Mark
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Untested try on a copy of your data:
VBA Code:
Sub FetchDateAndTime()
Dim Lrw As Long
Lrw = Cells(Rows.Count, "B").End(xlUp).Row
With Range("C2:C" & Lrw)
    .Formula = "=DATE(LEFT(B2,4),MID(B2,6,2),MID(B2,9,2))"
    .NumberFormat = "mm/dd/yyyy"
End With
With Range("D2:D" & Lrw)
    .Formula = "=RIGHT(B2,5)+0"
    .NumberFormat = "hh:mm"
End With
With Range("C2:D" & Lrw)
    .Calculate
    .Value = .Value
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,425
Messages
6,124,826
Members
449,190
Latest member
rscraig11

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