Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Record Number of sum to formula based cell - Excel

0

Hi Team,

I am looking for the solution for recording the sum of quantity to respective cells.

Please advise for solution to record the sum value, whenever there is change in rate (positive) from present rate than the given quantity to add to Positive column and whenever there is change is rate (negative) from present rate than the given quantity to add to Negative column

For example, If the rate is changed from 1 to 2 (positive move), than the given quantity i.e. 100 in quantity column to add to positive column and If the rate is changed from 3 to 2 (negative move), than the given quantity i.e. 200 in quantity column to add to Negative column and so on. 

You have already given same kind of solution to my previous query i.e. "Record Number of counts to formula based cell - Excel" Please refer to attachment.

Based on your previous solution, I have tried to incorporate the same thing to the solve the query, but unable to figure out the same.

I have attached the excel sheet for your reference.

Trust you understand the requirement. Please let me know for more understanding.

Request you to please help for the solution.

Regards,

Answer
Discuss

Discussion

Hi Sunil

Sorry but I can't understand your question (or why you'd want to sum quantities - rather than differitials- when a rate change occurs, if this is a manufacturing scenario).

You seem to refer to a VBA (not formula-based) solution I provided in April/May 2021 under Record Number of counts to formula based cell - Excel and say "... I have tried to incorporate the same thing to the solve the query" but you did not attach the .xlsm file showing how you modified the macro (please do so).

In this case too, are all values (in both columns C and D) of Sheet 2 updated remotely by a third party plug-in?

You say what should happen if the rate changes positively or negatively but what should happen if the rate remains unchanged?

In your real case, how many rows will change? At what kind of frequency (say twice per hour)? All changing at the same time, potentially?

Once again, please edit your original question to explain.
John_Ru (rep: 6142) Mar 15, '22 at 10:45 am
Add to Discussion

Answers

0
Selected Answer

Sunil

In my answer below, I've made some guesses based on your question. I've assumed this is linked to a remote file (as per the link in the Discussion to your question) and that nothing need to happen to your "positive" and "negative2 value (in E and F) if the rate stays unchanged.

I've left your VLOOKUP formula in place (in columns Cand D of Sheet2 of the attached .xlsm file) but in green cells (rows 17 and 18), I changed the reference to the revised remote .xlsx file, Remote data link for Sum (1).xlsx (for test purposes- you'd need to re-make the VLOOKUP references for those to get it to work).

The code beow does what your question requests (I believe) and is commanted for your convenience. Chnages in the remite file with trigger the Worksheet_Calculate event and cause this macro to run (and update sheet 1 of the .xlsm file):

Private Sub Worksheet_Calculate()

Dim Rpt As Range, Cll As Range

' prevent retriggering
Application.EnableEvents = False
Application.Calculation = xlCalculationManual

'run through cells and modify Report if value has changed
For Each Cll In Sheet2.Range("C3:C25")
    If IsNumeric(Cll.Value) Then

        Set Rpt = Sheet1.Range(Cll.Address)

        ' compare new values with those in Rpt
        Select Case Cll.Value - Rpt.Value
            Case Is > 0 ' write to E
                Rpt.Offset(0, 2).Value = Rpt.Offset(0, 2).Value + Cll.Offset(0, 1).Value
            Case Is < 0 ' write to F
                Rpt.Offset(0, 3).Value = Rpt.Offset(0, 3).Value + Cll.Offset(0, 1).Value
            Case Is = 0
                ' Do nothing not sure what happens here!!
            Case Else
                ' ### for errors?
        End Select
        'write new values to B, C and D
        Rpt.Offset(0, -1).Value = Cll.Offset(0, -1).Value
        Rpt.Value = Cll.Value
        Rpt.Offset(0, 1).Value = Cll.Offset(0, 1).Value
    End If
Next Cll
' restore conditions
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic

End Sub

Hope this helps.

Discuss

Discussion

Thank you very much John. 
I understand my query and provide solution as I needed. 
Thank you. 
SunilA (rep: 58) Mar 16, '22 at 4:04 am
Glad that worked. Thanks for selecting my answer Sunil. 
John_Ru (rep: 6142) Mar 16, '22 at 4:50 am
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login