sumif issues

dgrimm

Board Regular
Joined
Sep 17, 2007
Messages
159
I am trying to sum according to year and I am getting an application or object defined error.

Here is the piece of code that is getting the error.

Sheets(wsr).Select
Set speccol = Range("d9:d" & wsrcnt)
Set aggcol = Range("e9:e" & wsrcnt)
Set specpd = Range("j9:j" & wsrcnt)
Set aggpd = Range("k9:k" & wsrcnt)
Set specult = Range("l9:l" & wsrcnt)
Set aggult = Range("k9:k" & wsrcnt)

For i = 0 To difyr
Sheets(wsr).Range("c" & newwsrcnt + 2 + i).Formula = "=SumIf((""b9:b"" & wsrcnt), minyr + i, speccol)"
Next i

The line after For i = 0 to difyr.

I don't know if it is my "" in the formula or what. I have speccol dimmed as a range (which has a lot of blanks in it). If you need more info please ask away. All the other variables I have have been using before, the only new one is the speccol variable. So I am believing it is with that or just my equation in general.

Any help would be greatly appreciated.



Thanks in advance

Dave
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
The range quotes can be confusing when you already have quotes to indicate your formula. It might be a little easier to break it up and build the range outside of the formula in a variable and reference it.

Here is what that loop might look like:
Code:
    Dim myRange as String
    For i = 0 To difyr
        myRange = "B9:B" & wsrcnt
        Sheets(wsr).Range("c" & newwsrcnt + 2 + i).Formula = "=SumIf(" & myRange & "," & minyr + i & "," & speccol.Address & ")"
    Next i
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,841
Members
452,948
Latest member
UsmanAli786

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