• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Problem With Running Balance

Hello Friends,

I have a workbook having two sheets(sheet2 and sheet3).I have write one code with in both the sheets to calculate the running balance.
The code in the first sheet working well , but the second sheet do nothing.
The reason in the 2nd sheet is that the calculation is start from third row.
Now how i can set the same code for the 2nd sheet to start calculation from the 3rd row.
Code for sheet 2
HTML:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim i As Long
i = Application.WorksheetFunction.CountA(Sheet2.Range("A:A"))
On Error Resume Next
Sheet2.Cells(i, "D").Value = Val(Sheet1.Cells(i - 1, "D")) + Val(Sheet2.Cells(i, "B")) - Val(Sheet2.Cells(i, "C"))
End Sub

I have upload the file also.
 

Attachments

  • Running Balance.xlsm
    15.3 KB · Views: 1
Mohammed

Try this code in the workbook module
Remove the existing code in the worksheet modules

Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim i As Long
Application.EnableEvents = False
On Error GoTo eh
i = Range("A" & Rows.Count).End(xlUp).Row
Sh.Cells(i, "D").Value = Sh.Cells(i - 1, "D").Value + Sh.Cells(i, "B").Value - Sh.Cells(i, "C").Value

eh:
Application.EnableEvents = True

End Sub

see attached file:
 

Attachments

  • Running Balance.xlsm
    15.1 KB · Views: 1
Back
Top