In Column O, starting from Cell O3, the value is =H3/$D$3. I then drag and drop the formula downwards. So Cell O4's value is =H4/$D$3 and so on etc..
But whenever I encounter a blank row, for example if Row 6 is a blank row, I would like the formula in Column O to "reset". So for Cell O7's value, I would like it to be =H7/$D$7, (instead of H7/$D$3) and then drag and drop the values until there is another blank row, then "resetting the value" in Column O again.
The problem with the excel macro below, is that it doesnt lock the Cell D values. So the output would be =H3/$D$3, =H4/$D$4, =H5/$D$5 etc.
How would I fix the macro so the output would be =H3/$D$3, =H4/$D$3, =H5/$D$3 etc. ?
Thanks.
But whenever I encounter a blank row, for example if Row 6 is a blank row, I would like the formula in Column O to "reset". So for Cell O7's value, I would like it to be =H7/$D$7, (instead of H7/$D$3) and then drag and drop the values until there is another blank row, then "resetting the value" in Column O again.
The problem with the excel macro below, is that it doesnt lock the Cell D values. So the output would be =H3/$D$3, =H4/$D$4, =H5/$D$5 etc.
How would I fix the macro so the output would be =H3/$D$3, =H4/$D$3, =H5/$D$3 etc. ?
Thanks.
VBA Code:
Sub ResetFormulaOnBlankRow()
Dim ws As Worksheet
Dim lastRow As Long
Dim i As Long
Dim denominator As Double
Set ws = ThisWorkbook.Sheets("Sheet1") ' Change the sheet name as needed
lastRow = ws.Cells(ws.Rows.Count, "H").End(xlUp).Row
For i = 3 To lastRow
If ws.Cells(i, 1).Value = "" Then
denominator = ws.Cells(i, 4).Value
Else
ws.Cells(i, 15).Formula = "=" & "H" & i & "/" & "$D$" & i
End If
Next i
End Sub