Macro to match the sum of both the colum n

harshab6

Active Member
Joined
Oct 1, 2008
Messages
254
Hi

I want a macro which could find the sum of column E:E and R:R If sum matches then give a message both E and R Matches would you like the macro run further Yes or no, If the user selects yes then macro should run further, if the sum of E and R column doesn't match then give the msg as sum doesn't match please check.

Thanks and Regards,
Harsha
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
This will do what you describe, but I don't understand why you want to repeat the macro if the values match. It will just give the same results. In an event here is the code.

Code:
Sub t()
Dim rng1 As Range, rng2 As Range, ans As Variant
CYC:
With ActiveSheet
    Set rng1 = .Range("E2", .Cells(Rows.Count, 5).End(xlUp))
    Set rng2 = .Range("R2", .Cells(Rows.Count, 18).End(xlUp))
    If Application.Sum(rng1) = Application.Sum(rng2) Then
        ans = MsgBox("The values match.  Do you want to repeat the test?", vbYesNo + vbQuestion, "CONTINUE?")
            If ans = vbYes Then
                GoTo CYC:
            End If
    Else
        ans = MsgBox("The values do not match.  Please validate entries.")
    End If
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,901
Messages
6,175,277
Members
452,629
Latest member
SahilPolekar

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