• 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.

My Code for Running Total Not working for specific sheet

Previously in this form i was helped to correct my vba code for running total.But that time the code is for the whole workbook and the code was running very well.

But now according to my need i want to set the code only for a specific sheet.Not for the whole workbook.
I want the code to set only for sheet 1.

I have change the code for the sheet1 only.But it is not working.

It should be note that i enter the data through user form not manually.

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

eh:
Application.EnableEvents = True
End Sub

I request you that please let me help to set the code only for a specific sheet not for the whole workbook.
 
Without example file??
You are using
Code:
Sh.Cells
So I think you have to add
Code:
Set Sh = Worksheets("your sheet name")
Something like this
Code:
Dim i As Long
Dim Sh As Worksheet
Set Sh = Worksheets("Your sheet name")
Application.EnableEvents = False
On Error GoTo eh
i = Range("D" & Rows.Count).End(xlUp).Row
Sh.Cells(i, "G").Value = Sh.Cells(i - 1, "G").Value + Sh.Cells(i, "E").Value - Sh.Cells(i, "F").Value

eh:
Application.EnableEvents = True
End Sub
 
Last edited:
Back
Top