using difference rather than

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Using a Difference rather than Less than or More than

Using a Difference rather than Less than or More than

resolvedResolved · High Priority · Version 2013

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

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Create a unique items table from a duplicating table

1. Ensure that your list has column headings
2. Select the entire list
3. From the menu bar, select DATA, FILTER, ADVANCED FILTER
4. Select "Filter the list, in place", and tick the "Unique Records Only" box
5. Click OK, filtered list appears.

View all Excel hints and tips


Server loaded in 0.07 secs.