Livin404
Well-known Member
- Joined
- Jan 7, 2019
- Messages
- 743
- Office Version
- 365
- 2019
- Platform
- Windows
I found out with the assistance from “offthelip” this is not an Excel Date Time Format. Image A is Column D before any VBA is launched. With my limited capabilities I had to break this down into two different VBAs. One to get rid of the date leaving the time, and the other to add zeros to reflect a 24 hour clock, (Image B and C respectfully). The first VBA (B) is also taking out the “Roll” in Roll Call. I would love to have some sort of line to correct that. The second VBA (C) is adding a 0 to the blank lines. I am looking for a line that will prevent that from happening. Thank you in advance for anyone who may consider helping. I did try different forms of the empty statements “” and isempty type of statements to no avail. Any assistance would greatly be appreciated.
VBA Code:
Sub IsolateTime()
Dim cel As Range
Range("D1:D100").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
VBA Code:
[ATTACH type="full"]24996[/ATTACH]Sub twenty_four_hour_Clock()
With Range("D1", Range("D" & Rows.Count).End(xlUp))
x = .Address
.NumberFormat = "@"
.Value = Evaluate("if(len(" & x & ")=3,""0""&" & x & "," & x & ")")
.Value = Evaluate("if(len(" & x & ")=2,""00""&" & x & "," & x & ")")
End With
End Sub