Solved

how to identify date/time entries missing in a sequence

Posted on 2013-06-21
11
191 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 50

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 50

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 50

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 50

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 50

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

685 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