Hello

There is some misalignment when calculating in column J when button clicked.

Will appreciate if anyone can help me to correct it in code below

For the Following representation

<tbody>

</tbody>

Thanks

NimishK

There is some misalignment when calculating in column J when button clicked.

Will appreciate if anyone can help me to correct it in code below

For the Following representation

ROWS | H | I | J | ||

1 | NAME | AMOUNT | TOTAL | ||

2 | Xxxxx | 5000 | |||

3 | 6000 | ||||

4 | 4000 | 15000 | =sum(H2:H4) | This is last used row ref when btn clicked | |

5 | yyyyy | 2000 | |||

6 | 3000 | 5000 | =sum(H5:H6) | This is last used row ref when btn clicked | |

7 | xtxtxt | 3650 | |||

8 | 2000 | ||||

9 | 3350 | ||||

10 | 1500 | 10500 | =sum(H7:H10) | This is last used row ref when btn clicked |

<tbody>

</tbody>

Code:

```
Private Sub Button_Click()
Dim Ws As Worksheet
Set Ws = Worksheets("Sheet1")
Dim lRec As Long
Dim lstUsdRow As Long
lstUsdRow = (RgsWs.Cells.Find(What:="*", After:=Range("A1"), LookAt:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Row) + 1
Const StartRow As Long = 2
Dim newRow As Long
newRow = lstUsdRow
RgsWs.Cells(lstUsdRow, 7).Value = txtName.Text
For lRec = 1 to CurRec
Ws.Cells(newRow, 8).Value = Amount$(lRec)
Ws.Cells(newRow, 9).Formula = "=SUM(H" & StartRow & ":H" & (curRec + 1) & ")"
newRow = newRow + 1
Next lRec
End Sub
```

NimishK

Last edited: