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

using difference rather than

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

ResolvedVersion 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:

Convert a column into row quickly in Excel 2010

Occasionally you might enter data into Excel vertically and then when you finish realize that actually it would look more clearer if it was represented in a horizontal format. If you follow these simple steps below, you can quickly change the data from going vertically to horizontally and vice versa.

First, select the column you want to convert into a row or a row into a column. Then right click and select Copy. Go to the sheet where you want to past this row as a column and select “Paste Special”. Remember to check the check-box “Transpose” and select “OK”.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.