Macro SUM values

NerakSeven

New Member
Joined
Jan 6, 2019
Messages
14
Check in Sheet 1 the sum of the field “Long” is equal “Long” in Sheet 2 for the same “code” where “Ap” is “0”. If this is not correct put in sheet 2 in column “Sum” the value “Not correct”.



Sheet 1
Code
Long
Ap
15-15
100
0
16-16
50
1
15-15
100
0
14-14
50
0
14-14
50
0
16-16
5
1

<tbody>
</tbody>


Sheet 2
Code
Long
Sum
15-15
2350
Not correct
14-14
100

16-16
87


<tbody>
</tbody>
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Based on your example, place this formula in cell C2 on Sheet 2 and copy down to C4:
Code:
=IF(SUMIFS(Sheet1!B$2:B$7,Sheet1!A$2:A$7,'Sheet 2'!A2,Sheet1!C$2:C$7,0)=B2,"","Not correct")
 
Upvote 0
Try
I assume this is I column A though C in both sheets and the sheets are named Sheet1 and Sheet2.

Code:
Sub csum()
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim lr1 As Long
Dim lr2 As Long
Set ws1 = Sheets("Sheet1")
Set ws2 = Sheets("Sheet2")
lr1 = ws1.Cells(Rows.Count, "A").End(xlUp).Row
lr2 = ws2.Cells(Rows.Count, "A").End(xlUp).Row
For x = 2 To lr2
    If Cells(x, "B") <> Application.WorksheetFunction.SumIfs(ws1.Range("B2:B" & lr1), ws1.Range("C2:C" & lr1), 0, ws1.Range("A2:A" & lr1), Cells(x, "A")) Then
        ws2.Cells(x, "C") = "not correct"
    End If
Next x

End Sub
 
Upvote 0
Thanks works sums but not when "Ap" is zero.

Again Thanks



Try
I assume this is I column A though C in both sheets and the sheets are named Sheet1 and Sheet2.

Code:
Sub csum()
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim lr1 As Long
Dim lr2 As Long
Set ws1 = Sheets("Sheet1")
Set ws2 = Sheets("Sheet2")
lr1 = ws1.Cells(Rows.Count, "A").End(xlUp).Row
lr2 = ws2.Cells(Rows.Count, "A").End(xlUp).Row
For x = 2 To lr2
    If Cells(x, "B") <> Application.WorksheetFunction.SumIfs(ws1.Range("B2:B" & lr1), ws1.Range("C2:C" & lr1), 0, ws1.Range("A2:A" & lr1), Cells(x, "A")) Then
        ws2.Cells(x, "C") = "not correct"
    End If
Next x

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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