Having problem with Date

ru_1985

New Member
Joined
Oct 4, 2006
Messages
35
Given a list of dates. Would it be able to check the list of dates, sort it in ascending order and check whether there is any missing date, if there is missing date can it be able to insert a blank row into where the missing date should be.

EXAMPLE

BEFORE
row 1 13/6/2005
row 2 14/6/2005
row 3 16/6/2005
row 4 17/6/2005

AFTER
row 1 13/6/2005
row 2 14/6/2005
row 3
row 4 16/6/2005
row 5 17/6/2005
 

Some videos you may like

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

acw

MrExcel MVP
Joined
Feb 13, 2004
Messages
4,814
Hi

Assumes the data is in column A, starting in row1. Inserts entire row.

Code:
Sub ddd()
  Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row).Sort key1:=Range("A1"), order1:=xlAscending, header:=xlNo
  Range("A2").Select
  While Not IsEmpty(ActiveCell)
    If ActiveCell <> ActiveCell.Offset(-1, 0) + 1 Then
      ActiveCell.EntireRow.Insert
      ActiveCell.Offset(2, 0).Select
    Else
      ActiveCell.Offset(1, 0).Select
    End If
  Wend
End Sub

HTH

Tony
 

ru_1985

New Member
Joined
Oct 4, 2006
Messages
35
hihih... thank you very much for the code,
by the way, if my dates contain time, Ex: [m-dd-yy hh:mm]


Example

2006-09-01 10:23
2006-09-01 14:54
2006-09-03 09:34
2006-09-04 07:45

how will the source code be like?

Thank you for your great help.
 

agihcam

Well-known Member
Joined
Jan 16, 2006
Messages
1,624
Hi -

I have modified Tony's code, give it a try;
Code:
Sub ddd()
Application.ScreenUpdating = False
  Range("a1:a" & Cells(Rows.Count, 2).End(xlUp).Row).Sort key1:=Range("a1"), order1:=xlAscending, header:=xlNo
  Columns("A:A").TextToColumns Destination:=Range("B1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False, _
        Semicolon:=False, Comma:=False, Space:=True, Other:=False, FieldInfo _
        :=Array(Array(1, 1), Array(2, 1), Array(3, 1))
  Range("b2").Select
  While Not IsEmpty(ActiveCell)
    If ActiveCell <> ActiveCell.Offset(-1, 0) + 1 And ActiveCell <> ActiveCell.Offset(-1, 0) Then
      t = ActiveCell - ActiveCell.Offset(-1, 0)
      ActiveCell.Resize(t - 1).EntireRow.Insert
      ActiveCell.Offset(t, 0).Select
    Else
      ActiveCell.Offset(1, 0).Select
    End If
  Wend
  Columns("b:d").Delete
  Application.ScreenUpdating = True
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,109,494
Messages
5,529,192
Members
409,857
Latest member
KailuaTown
Top