Solved

how to identify date/time entries missing in a sequence

Posted on 2013-06-21
11
199 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 52

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 52

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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

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 52

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 52

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 52

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

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!

Question has a verified solution.

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

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

624 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