Here's the formatted BBcode:
Step-by-step guide on how to create a macro that will insert a new row with the same date when you click on a cell with a date in it:
- Open your Excel workbook and go to the worksheet where you want to add the macro.
- Press to open the Visual Basic Editor.
- In the Visual Basic Editor, go to Insert Module to create a new module.
- In the new module, paste the following code:
Formula:
Sub InsertRowWithDate()
Dim selectedDate As Date
Dim lastRow As Long
selectedDate = ActiveCell.Value
lastRow = Cells(Rows.Count, 1).End(xlUp).Row
For i = lastRow To 2 Step -1
If Cells(i, 1).Value = selectedDate Then
Rows(i + 1).Insert Shift:=xlDown
Cells(i + 1, 1).Value = selectedDate
End If
Next i
End Sub
- Save the module and close the Visual Basic Editor.
- Go back to your worksheet and select the cell with the date you want to insert a new row for.
- Click on the Developer tab in the ribbon (if you don't see it, go to File Options Customize Ribbon and check the Developer box).
- Click on the "InsertRowWithDate" button in the Controls group.
- A new row with the same date as the selected cell should now be inserted below it.
That's it! You can now use this macro to quickly insert new rows with the same date as any cell you select.