Two VBAs to isolate times

Livin404

Well-known Member
Joined
Jan 7, 2019
Messages
743
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I found out with the assistance from “offthelipthis 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
 

Attachments

  • two vba.JPG
    two vba.JPG
    63.2 KB · Views: 6

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
The second portion of this question is complete.
 
Upvote 0

Forum statistics

Threads
1,215,235
Messages
6,123,786
Members
449,125
Latest member
shreyash11

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