Sean has attended:
Excel VBA Introduction course
Excel VBA Intermediate course
Using a Difference rather than Less than or More than
I'm trying to create a Code to insert a row whenever the following applies:
active cell is more than 1 second difference to activecell.offset(-1,0)
then i'll put it into a do loop to work its way down the list.
Anyone know how to use differences?
RE: Using a Difference rather than Less than or More than
Hi Sean.
Thank you for the forum question.
Please have a look at the code below.
Sub Test()
Range("b2").Select
Do Until ActiveCell = ""
If TimeSerial(Hour(ActiveCell), Minute(ActiveCell), Second(ActiveCell)) <> _
TimeSerial(Hour(ActiveCell.Offset(-1, 0)), Minute(ActiveCell.Offset(-1, 0)), Second(ActiveCell.Offset(-1, 0)) - 1) _
And TimeSerial(Hour(ActiveCell), Minute(ActiveCell), Second(ActiveCell)) <> _
TimeSerial(Hour(ActiveCell.Offset(-1, 0)), Minute(ActiveCell.Offset(-1, 0)), Second(ActiveCell.Offset(-1, 0)) + 1) _
And TimeSerial(Hour(ActiveCell), Minute(ActiveCell), Second(ActiveCell)) <> _
TimeSerial(Hour(ActiveCell.Offset(-1, 0)), Minute(ActiveCell.Offset(-1, 0)), Second(ActiveCell.Offset(-1, 0))) Then
ActiveCell.Font.Color = vbRed
End If
ActiveCell.Offset(1, 0).Select
Loop
End Sub
Kind regards
Jens Bonde
Microsoft Office Specialist Trainer
Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us
London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector