[VBA] SumIf Errors

ExcelNooberino

New Member
Joined
Jan 2, 2019
Messages
43
Office Version
  1. 2016
Platform
  1. Windows
Hello everyone,

I keep trying to achieve a formula that allows me to sum some cells in a different sheet than the one I wanted posted so I've developed a code such as this one below:

Sub SumData()
Dim LastRow As Long
Dim FirstRow As Long


LastRow = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
FirstRow = Sheets("Sheet1").Range("H2").Row
Range("Home!A1") = Application.WorksheetFunction.SumIf(Range(Home!E" & FirstRow & ":Home!E" & LastRow & "), "EX20", Range(Home!H" & FirstRow & ":Home!H" & LastRow & "))

End Sub

I keep getting syntax errors and so on no matter how I switch it up, I need some help! :(
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Welcome to the board.

Assuming you're searching for the text string "EX20" and not the value from cell EX20, try:

Code:
Sub SumData()
Dim LastRow As Long
Dim FirstRow As Long


LastRow = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
FirstRow = Sheets("Sheet1").Range("H2").Row
Range("Home!A1") = _
    Application.WorksheetFunction.SumIf(Range("Home!E" & FirstRow & ":Home!E" & LastRow), _
                                        "EX20", _
                                        Range("Home!H" & FirstRow & ":Home!H" & LastRow))

End Sub
 
Last edited:
Upvote 0
Thanks in advance!
That did fix the issue, however, the I guess the sheet I want it's not being recognized cuz the value I get from that sum keeps staying on zero :/
 
Upvote 0
Nevermind, silly of me.. I forgot to change the Home! to Sheet1! in the formula, now it works! Thank you so much man! :D
 
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