SumIF across sheets vba

Lauren123

New Member
Joined
Mar 16, 2018
Messages
28
I have this code, I dont know how to debug it. It always show Invalid procedure call or argument.

Sub Sumif()
Wk = ThisWorkbook.Name
Call Lastrowssub2
Workbooks(Wk).Worksheets("U-Main").Range("G11") = Application.WorksheetFunction.Sumif(Sheets("U-Detail").Range("J11:J" & LastRows), Sheets("U-Detail").Range("Z11:Z" & LastRows), Sheets("Draft").Cells("C2").Value)


End Sub



If someone can help I would be really grateful!
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Could you please post the code for your Lastrowssub2?
 
Upvote 0
Yes sure! Here it is!

Sub Lastrowssub2()


Wk_Name = ThisWorkbook.Name


LastRows = Workbooks(Wk_Name).Worksheets("U-Detail").Cells(Rows.Count, "C").End(xlUp).Row


End Sub
 
Upvote 0
Just noticed it's the formula that's wrong, try
Code:
Sub Sumif()
   With ThisWorkbook
      .Worksheets("U-Main").Range("G11").Value = Application.Worksheetfunction.Sumif(.Sheets("U-Detail").Range("Z:Z"), .Sheets("Draft").Range("C2").Value, .Sheets("U-Detail").Range("J:J"))
   End With
End Sub
If you are trying to sum col J, then swap the J & Z ranges round
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,774
Members
452,353
Latest member
strainu

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