Solved

how to identify date/time entries missing in a sequence

Posted on 2013-06-21
11
180 Views
Last Modified: 2013-07-05
hi Folks
Am attaching a file with the following. This information is captured every 2 minutes but sometimes the capture goes askew so there's a gap e.g in the file attached there's a gap of 6 minutes as opposed to two. (a) how could I highlight those gaps (was thinking of using a helper cell combined with conditional formatting? and (b) is there a way to automatically insert a number of rows corresponding to the missing entries e.g. to insert two rows between 9 and 10 to show 2 2 minute intervals are missing.. thanks as always
checking-sequence-is-missing.xlsm
0
Comment
Question by:agwalsh
  • 6
  • 5
11 Comments
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 39265325
Hi,

pls try

Sub Makro1()

For n = Range("A" & Rows.Count).End(xlUp).Row To Range("A3").Row Step -1
    Set Cell = Range("A" & n)
    If CInt(Format(Cell.Offset(-1, 0).Value - Cell, "n")) > 2 Then
        Cell.Insert Shift:=xlDown ' , CopyOrigin:=xlFormatFromLeftOrAbove
        Cell.Offset(-1, 0).Value = DateAdd("n", -2, Cell.Value)
    End If
Next
End Sub

Open in new window

Regards
0
 

Author Comment

by:agwalsh
ID: 39265357
So presumably, create a macro, use this code. Do I need to highlight the column first and then try it? Thanks
0
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 39265363
Hi,

the macro search all the entries from range A3 to the bottom, if ou want another range just tell me

regards
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

Author Comment

by:agwalsh
ID: 39265396
Yes, the user would have different columns that they want to do this on so if it could be set up to work on the highlighted column - that would be ideal :-) thank you
0
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 39265675
Hi,

use it on the selected column

Sub Makro1()
lngCol = Selection.Column
For lngRow = Cells(Rows.Count, lngCol).End(xlUp).Row To Cells(3, lngCol).Row Step -1
    Set Cell = Cells(lngRow, lngCol)
    If CInt(Format(Cell.Offset(-1, 0).Value - Cell, "n")) > 2 Then
        Cell.Insert Shift:=xlDown ' , CopyOrigin:=xlFormatFromLeftOrAbove
        Cell.Offset(-1, 0).Value = DateAdd("n", -2, Cell.Value)
        n = n + 1
    End If
Next
End Sub

Open in new window

Regards
0
 

Author Comment

by:agwalsh
ID: 39274341
ooh, let me try this. Thank you :-)
0
 

Author Comment

by:agwalsh
ID: 39274360
Tried this with selecting entire column and I got this message :
This lngCol was highlighted and I got the messaage: Compile Error, Variable not defined.
And the first lngCol = was highlighted.

Thank you :-)
0
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 39277087
Hi,

It means you  have to define the variables before using them

Option Explicit
Sub Makro1()
Dim lngCol As Long
Dim lngRow As Long
Dim Cell As Range
Dim n As Long
lngCol = Selection.Column
For lngRow = Cells(Rows.Count, lngCol).End(xlUp).Row To Cells(3, lngCol).Row Step -1
    Set Cell = Cells(lngRow, lngCol)
    If CInt(Format(Cell.Offset(-1, 0).Value - Cell, "n")) > 2 Then
        Cell.Insert Shift:=xlDown ' , CopyOrigin:=xlFormatFromLeftOrAbove
        Cell.Offset(-1, 0).Value = DateAdd("n", -2, Cell.Value)
        n = n + 1
    End If
Next
End Sub

Open in new window

Regards
0
 

Author Comment

by:agwalsh
ID: 39277476
hi
I've tried that (see attached file with macro) and yep, works perfectly to add in a new 2 minute row every time it's run. However, I was wondering would it be possible to do the following (see attached sheet) - just show a text entry missing - every time there was a row out of sequence. Thank you so much again :-)
checking-sequence-is-missing-wit.xlsm
0
 
LVL 49

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39289834
Hi,

pls try this

Option Explicit

Sub Makro1()
Dim lngCol As Long
Dim lngRow As Long
Dim Cell As Range
Dim Idx As Long
lngCol = Selection.Column

For lngRow = Cells(Rows.Count, lngCol).End(xlUp).Row To Cells(3, lngCol).Row Step -1
    Set Cell = Cells(lngRow, lngCol)
    If CInt(Format(Cell.Offset(-1, 0).Value - Cell, "n")) > 2 _
            And Cell.Offset(-1, 0).Value <> "" And Cell.Value <> "" Then
        For Idx = 1 To CInt(Format(Cell.Offset(-1, 0).Value - Cell, "n")) / 2 - 1
            Cell.Insert Shift:=xlDown
        Next
    End If
Next
End Sub

Open in new window

Regards
0
 

Author Closing Comment

by:agwalsh
ID: 39301438
Ab-solutely- brilliant. Did exactly what I wanted... thank you:-0
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question