Do loop help

bradyj7

Board Regular
Joined
Mar 2, 2011
Messages
106
Hi there,

I a file with time (seconds), speed and headings. I wish to put a number in a column each time a new condition defined by me occurs. Currently I have the code below, which inserts 1,2,3 etc in a column each time a vehicle changes direction
Code:
Range("AL1").FormulaR1C1 = "conditions"

i = 1

Range("AL2").Select

   do loop to check for direction change:
 
    Do

        If  ActiveCell.Offset(0, -33).Text = "Change of heading" Then

        ActiveCell.Value = i
        i = i + 1

        End If

    ActiveCell.Offset(1, 0).Select

    Loop Until IsEmpty(ActiveCell.Offset(0, -1))

Now I want to change it so that, it puts a marker every 30 seconds. I have seconds in the previous column 1,2,3,4 etc, so I want to put a marker at every multiple of 30. This is what I have so far

Code:
Range("AL1").FormulaR1C1 = "conditions"

i = 1

Range("AL2").Select

   do loop to mark every 30 seconds:
 
    Do

        If  ActiveCell.Offset(0, -1). = **a multiple of 30** Then

        ActiveCell.Value = i
        i = i + 1

        End If

    ActiveCell.Offset(1, 0).Select

    Loop Until IsEmpty(ActiveCell.Offset(0, -1))

Could someone help me define the multiple of 30 piece of code.

Thank you
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Try
Code:
 Dim i
 Do
        If ActiveCell.Offset(0, -1) Mod 30 = 0 Then  '= **a multiple of 30** Then
             i = i + 1
            ActiveCell.value = i
       End If
            ActiveCell.Offset(1, 0).Select
Loop Until IsEmpty(ActiveCell.Offset(0, -1))
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,548
Members
452,927
Latest member
rows and columns

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