Solved

how to identify date/time entries missing in a sequence

Posted on 2013-06-21
11
163 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 48

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 48

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
 

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 48

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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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 48

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 48

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
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…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now