Livin404
Well-known Member
- Joined
- Jan 7, 2019
- Messages
- 743
- Office Version
- 365
- 2019
- Platform
- Windows
Good evening, I am trying to figure out how I can isolate a 24 hour time from a Custom Date format (dd mmm yyyy hhmm) in Excel using VBA. Image A illustrates Column D prior to my VBA. Image B illustrates what happens when I use the VBA. Image C is how I would like it to appear. I'm sure a need a code that will change the format to text in order to keep the leading 0. Also I need to be mindful to have it change only the cells with times. I want to avoid having Value errors in the blank columns. Lastly if it's not too difficult, a code I can use to show there are no errors would be great.
Thank you,
Thank you,
VBA Code:
[ATTACH type="full"]24937[/ATTACH]Sub IsolateTime()
Dim cel As Range
Range("D2").Select
Range(Selection, Selection.End(xlDown)).Select
For Each cel In Application.Selection.Cells
cel.Value = Right(cel.Text, 4)
Next cel
Selection.NumberFormat = "@"
End Sub