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

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
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
 
Upvote 0
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.
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,507
Messages
6,114,029
Members
448,543
Latest member
MartinLarkin

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
Back
Top