Good Evening,

Livin404

Well-known Member
Joined
Jan 7, 2019
Messages
774
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have a listing of scheduled flights, and they are listed by departure dates and time. There may be days there are no flights (see image Oct 21 for example). I would like it to insert a date 21 Oct 2020 0000. Just one date, it doesn't have to match the previous or following days numbers. Once that is done I'm hoping to insert "NO DEPARTURES". In Column A that newly inserted row should be blank except the date which was added. I did find a code which has got the general idea date insertion. See below.

VBA Code:
Sub insertdate()
Dim rr As Date
Dim x As Long, rw As Long, diff As Long
Range("D300").End(xlUp).Select
With Selection
 rw = .Row
 rr = Int(.Value)
 .Offset(1, 0).Select
End With
Selection = Now()
diff = Int(Selection.Value - rr)
s = InputBox("Please enter sales amount.")
Cells(rw + 1, 2) = s
If diff > 0 Then
 Range(Cells(rw + 1, 1), Cells(rw + diff - 1, 1)).Select
 Selection.EntireRow.Insert
 For x = 1 To diff - 1
 rw = rw + 1
 Cells(rw, 1) = rr + 1
 Cells(rw, 2) = "0"
 rr = rr + 1
 Next
End If
End Sub
 

Attachments

  • MISSING DATE.JPG
    MISSING DATE.JPG
    21.5 KB · Views: 13

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hello,

does this work as expected?

VBA Code:
Sub ADD_MISSING_DATES()
    Application.ScreenUpdating = False
    For MY_ROWS = Range("D" & Rows.Count).End(xlUp).Row To 2 Step -1
        If Range("D" & MY_ROWS).Value - Range("D" & MY_ROWS - 1).Value > 1 Then
            For MY_ADD = 2 To Range("D" & MY_ROWS).Value - Range("D" & MY_ROWS - 1).Value
                Rows(MY_ROWS).Insert
                Range("D" & MY_ROWS).Value = Range("D" & MY_ROWS + 1).Value - 1
                Range("A" & MY_ROWS).Value = "NO DEPARTURE"
            Next MY_ADD
     End If
    Next MY_ROWS
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,931
Messages
6,175,465
Members
452,645
Latest member
Tante

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