Automate Deleting Duplicate Dates Insert Rows Make Date Entries

How to automatically remove duplicate date entries, automate multiple rows insertion and automate date entries in the inserted rows. Often we need to remove duplicate entries against duplicate dates and make missing entries between the last entered date and the end of the month date. This post explains how to determine the last day of the month. Then the macro detects the last date of entry. The VBA code next automatically inserts the required number of rows for further date and data entries. Watch the video below:

Watch this video on YouTube.

Here’s the complete VBA code which you can alter or optimize for your own automated solution:

Sub findDuplicates()
Dim i As Long, lastRow As Long
lastRow = Sheets(“Sheet1”).Range(“A” & Rows.count).End(xlUp).Row
Dim employeeno As Long
Dim lastDayofMonth As Integer

Cells(2, 3) = “=DATE(YEAR(RC[-1]),MONTH(RC[-1])+1,0)”
lastDayofMonth = Day(Cells(2, 3))
MsgBox “The last day of date is ” & lastDayofMonth

employeeno = InputBox(“Enter employee number”)

For i = 2 To lastRow

If Cells(i, 1) = employeeno And Cells(i, 2) = Cells(i + 1, 2) Then
Cells(i + 1, 2).EntireRow.Delete
End If

Next i


For i = 2 To lastRow
If Cells(i, 1) = employeeno Then
Cells(i + 1, 1).Select
End If

Next i

Dim myvalue As Long

myvalue = ActiveCell.Row

MsgBox “myvalue is ” & myvalue

dayofLastDateEntry = Day(Cells(myvalue – 1, 2))

Rows(ActiveCell.Row & “:” & ActiveCell.Row + (lastDayofMonth – dayofLastDateEntry) – 1).Insert shift:=xlDown

For i = myvalue To ((myvalue) + (lastDayofMonth – dayofLastDateEntry – 1))
Cells(i, 1) = employeeno
Cells(i, 2) = Cells(i – 1, 2).Value + 1
Next i

End Sub

Further reading:

Insert multiple rows using VBA in Excel

Published by

Dinesh Kumar Takyar

Welcome to! My aim is to help you learn MS Excel including VBA. I always felt that a good way to learn something was to find solutions to problems in that domain. That is why I share these Excel videos with you. Mostly these are questions asked during my corporate training sessions. I've been training individuals and companies in computers since 1991. I did my B. Sc. (Vordiplom), M. Sc. (Diplom) and Ph.D. (Dr. rer. nat.) from Hamburg, Germany. The best thing about solving some of my visitor's questions is that I also gain new insights. For more Excel VBA solutions you may like to visit my YouTube channel: For a structured Excel VBA training course online you can visit:

Leave a Reply

Your email address will not be published. Required fields are marked *