If you placed it as I described, then
the macro should run everytime the sheet is recalculated.
This is consistent with your concept of using a formula to do the work.
I did note I had a typo in the code. This is the tested revision:
Private Sub Worksheet_Calculate()
Dim lastrow As Long
lastrow = Cells(Rows.Count, 2).End(xlUp).Row
For i = lastrow To 2 Step -1
If Application.CountA(Cells(i, "B"), Cells(i, "D"), Cells(i, "E")) <> 0
And _
Application.CountA(Cells(i - 1, "B"), Cells(i - 1, "D"), Cells(i - 1,
"E")) <> 0 Then
If Cells(i, "B") <> Cells(i - 1, "B") Or Cells(i, "D") <> Cells(i - 1,
"D") _
Or Cells(i, "E") <> Cells(i - 1, "E") Then
Rows(i).EntireRow.Insert
End If
End If
Next
End Sub
It worked for me when I hit F9 to force a calculate.
However, I am not sure what you are doing or how you will be changing your
worksheet. If this is a one time thing, then you don't want to use the
calculate event. You would go into the VBE (alt + F11) and choose Insert =>
Module from the menu. In the module you would put this code:
Public Sub AddRows()
Dim lastrow As Long
lastrow = Cells(Rows.Count, 2).End(xlUp).Row
For i = lastrow To 2 Step -1
If Application.CountA(Cells(i, "B"), Cells(i, "D"), Cells(i, "E")) <> 0
And _
Application.CountA(Cells(i - 1, "B"), Cells(i - 1, "D"), Cells(i - 1,
"E")) <> 0 Then
If Cells(i, "B") <> Cells(i - 1, "B") Or Cells(i, "D") <> Cells(i - 1,
"D") _
Or Cells(i, "E") <> Cells(i - 1, "E") Then
Rows(i).EntireRow.Insert
End If
End If
Next
End Sub
the go back to excel and if you wanted to run it you would go
Tools=>Macro=>Macros, select Addrows and hit the run button.
or stay in the VBE, click in the macro and hit F5 as you describe.
Whatever you do, like any other change to a workbook, you need to save the
workbook to save the macro.