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

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
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,214,812
Messages
6,121,699
Members
449,048
Latest member
81jamesacct

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