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
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

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
 

Forum statistics

Threads
1,141,146
Messages
5,704,550
Members
421,354
Latest member
Canary99

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top