Solved

how to identify date/time entries missing in a sequence

Posted on 2013-06-21
11
196 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 51

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 51

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
Technology Partners: 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 51

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 51

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 51

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

751 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