For Loop with data formatted as Time (hh:mm:ss)

Alex89

New Member
Joined
May 30, 2019
Messages
34
Hi everyone,

I'm trying to create a for loop that iterates through each row in Column M. The data in this column is formatted as a time (Hours:Minutes:Seconds), I would like to flag any data (by highlighting the cell in red) greater than or equal to 7 minutes (00:07:00).

The code I have now essentially turns all of the data in column M into a number format, something like 0.0001. I'm using this format as the criteria for the For Loop. In this instance, 7 minutes is equivalent to 0.0048611111. After all of the iterations have been made I want to switch the format back to (H:M:S), with the cells over 7 minutes highlighted in red.

Code:
Sub QA_TimeSpent()


Dim ctr As Long






Worksheets("Master Publisher Content").Range("M:M").Select
Selection.NumberFormat = "0.00"


For i = 3 To ctr


If Range(i, 13) > 0.0048611111 Then
        Range(i, 13).Select
        With Selection.Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .Color = 255
            .TintAndShade = 0
            .PatternTintAndShade = 0
        End With
    End If
    
Next i


 


Worksheets("Master Publisher Content").Range("M:M").Select
Selection.NumberFormat = "h:mm:ss"


End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Forum statistics

Threads
1,224,820
Messages
6,181,162
Members
453,021
Latest member
Justyna P

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