Isolate time from code

Livin404

Well-known Member
Joined
Jan 7, 2019
Messages
743
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Greetings, I've included an image of times and their text counterparts. What code could I use to isolate just the time? It would have to be the 24 hour clock with no colon and include zeros in front of the number such as 0005, 0325 etc. I tried something like (see below) just to experiment, and it left me with 0000 for each item. This is for sheet “72 Hr” and Column D. Thank you!

50013499-5BDD-4840-8577-E21790B3608B.jpeg


VBA Code:
VBA Code:
Sub TIME()

Range("D13") = Format(Date, "HHMM")

End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
How about
VBA Code:
Sub twenty_four_hour_Clock()
   With Range("D1", Range("D" & Rows.Count).End(xlUp))
      .NumberFormat = "@"
      .Value = Evaluate(Replace("if(@="""","""",if(isnumber(@),text(mod(@,1),""hhmm""),@))", "@", .Address))
   End With
End Sub
 
Upvote 0
How about
VBA Code:
Sub twenty_four_hour_Clock()
   With Range("D1", Range("D" & Rows.Count).End(xlUp))
      .NumberFormat = "@"
      .Value = Evaluate(Replace("if(@="""","""",if(isnumber(@),text(mod(@,1),""hhmm""),@))", "@", .Address))
   End With
End Sub
Perfect problem solved! Thank you, you're brilliant.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,861
Members
449,052
Latest member
Fuddy_Duddy

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