Help with vba to sum cells and also subtract cells

Gregm66

Board Regular
Joined
Jan 23, 2016
Messages
170
Hi everyone,

I have looked at different answers to this question with no success as when i run the vba my workbooks freezes and then wont do anything.

I have a worksheet called "Club Ledger" that i need to sum a range of cells in column C5 to C105001 and return the result to Cell F5..

Then sum the range G5 to G105001 and return the value to G5

and lastly i need to subtract cell G5 from F5 and return the value to H5

thanks in advance for any help
 
Sorry Trebor76,
My internet dropped out...
The first cell in column G that has a value is Cell G5... and same for H it is also H5 that holds the first value
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
The first cell in column G that has a value is Cell G5... and same for H it is also H5 that holds the first value

So this will put the desired results from your original request in cells F4:H4 whenever there's a change in C5:C105001 or G5:G105001:

Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

    If Not Intersect(Target, Range("C5:C105001,G5:G105001")) Is Nothing Then
        With Application
            .ScreenUpdating = False
            .EnableEvents = False
            Range("F4").Value = Evaluate("SUM(C5:C105001)")
            Range("G4").Value = Evaluate("SUM(G5:G105001)")
            Range("H4").Value = Evaluate("G4-F4")
            .EnableEvents = True
            .ScreenUpdating = True
        End With
    End If

End Sub

The above event code will have to on the "Club Ledger" tab.

HTH

Robert
 
Upvote 0
Thankyou a million Trebor76 problem solved that works perfectly your worth your weight in gold..

Thanks again

Regards
Greg
 
Upvote 0

Forum statistics

Threads
1,215,038
Messages
6,122,798
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top