SUMPRODUCT(--(MOD(OFFSET(C1,COUNTA(Dynamic Range),2)=1)) - Too few arguments - Why?

Poker Joe

New Member
Joined
Feb 12, 2015
Messages
30
Office Version
  1. 2019
Platform
  1. Windows
I need to enter a formula that will automatically update as I enter data daily. I'm attempting to use a dynamic range within the formula.

The formula in "I2" will find how many odd numbers are in the data (rows of data in C:G) for the last 5 days but I have to adjust the range every time I enter new data.

This is my attempt for a dynamic range within the formula in I2, =SUMPRODUCT(--(MOD(OFFSET(C1,COUNTA(C2:G1500,0,-5,1),2)=1))

Microsoft gives an error message that I've entered too few arguments. Once I select "OK" on the error message, the last "1" in the formula bar is highlighted.

I'm lost. Thanks in advance to anyone that can assist.

Book1.xlsx
ABCDEFGHIJ
1IDDateTeam1Team2Team3Team 4Team5OddEven
214492716338Last 5 Days=SUMPRODUCT(--(MOD(C17:G21,2)=1))=25-I2
324492827449
434492938573Last 5 Days
544493049684Dynamic Range=SUMPRODUCT(--(MOD(OFFSET(C1,COUNTA(C2:G1500,0,-5,1),2)=1))
6544931510195You've entered too few arguments for this function
764493238574After selecting OK on the Microsoft Error message, it highlights the last
874493349631"1" in the formula.
984493473496
10944935845101
11104493695385
121144937106496
13124493884968
14134493938573
15144494049634
16154494173495
171644942845106
18174494327449
19184494438573
20194494549684
212044946510195
22
23
Sheet1
Cell Formulas
RangeFormula
I2I2=SUMPRODUCT(--(MOD(C17:G21,2)=1))
J2J2=25-I2
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
You're missing a closing bracket to COUNTA(C2:G1500)
 
Upvote 0
You're missing a closing bracket to COUNTA(C2:G1500)

Doh! Those silly brackets get me every time.

That solves the error BUT my formula doesn't return the value I need. It returns "0" and should be 12.

Now, I'm really lost. Why? Why? Why?

Book1.xlsx
ABCDEFGHIJ
1IDDateTeam1Team2Team3Team 4Team5OddEven
211/1/202316338Last 5 Days1213
321/2/202327449
431/3/202338573Last 5 Days
541/4/202349684Dynamic Range0
651/5/2023510195You've entered too few arguments for this function
761/6/202338574After selecting OK on the Microsoft Error message, it highlights the last
871/7/202349631"1" in the formula.
981/8/202373496
1091/9/2023845101
11101/10/202395385
12111/11/2023106496
13121/12/202384968
14131/13/202338573
15141/14/202349634
16151/15/202373495
17161/16/2023845106
18171/17/202327449
19181/18/202338573
20191/19/202349684
21201/20/2023510195
22
23
Sheet1
Cell Formulas
RangeFormula
I2I2=SUMPRODUCT(--(MOD(C17:G21,2)=1))
J2J2=25-I2
I5I5=SUMPRODUCT(--(MOD(OFFSET(C1,COUNTA(C2:G1500),0,-5,1),2)=1))
 
Upvote 0
How about
Excel Formula:
=SUMPRODUCT(--(MOD(OFFSET(C1,COUNTA(C2:C1500),0,-5,5),2)=1))
 
Upvote 0
Solution
How about
Excel Formula:
=SUMPRODUCT(--(MOD(OFFSET(C1,COUNTA(C2:C1500),0,-5,5),2)=1))

That worked beautifully.

I did try to put that formula in another worksheet and change the OFFSET starting cell to C9,
Excel Formula:
=SUMPRODUCT(--(MOD(OFFSET(C9,COUNTA(C10:C1500),0,-5,5),2)=1))
because C1:C8 are blank and C9 is a header cell with text. It gave me a value 10 less than the value it should be. When I change the OFFSET starting cell to C1, and the COUNTA range to (C2:C1500) as you suggested for the other worksheet that I posted, it worked correctly.

I thought with OFFSET my start cell could be anywhere, then select the range. I see how you expanded the COUNTA range with "-5,5" vs. me having the range "C2:G1500". I need to review OFFSET and COUNTA again. I missed or assumed something.

Thank You! You're an Excel Hero for sure.
 
Upvote 0
Your formula starting in C9 should work assuming you don't have any empty cells in the data & that you don't have cell with "" below the data.
 
Upvote 1
Your formula starting in C9 should work assuming you don't have any empty cells in the data & that you don't have cell with "" below the data.
Hmmmm...I selected C9, Ctrl + Shift to the bottom of my data, then Find & Select, Go To Special, Blank Cells, No Cells Were Found.

Then did Find, "", No Cells were Found.

I expanded the range to include all of my data range, searched Blank Cells and Find "", didn't Find anything.

The data does have Formatting, Cell Fill, Bold Text, Colored Text on some of the cells but I don't think that would have any effect on the execution of the formula.

The formula you gave me works fine with C1 as the starting cell. I'm just curious why it won't with C9. As long as it works I'm good but it does drive me crazy not to know why it won't work the way I thought it should. I appreciate your help. It's not mystery that I have to solve right now. If I find something, I'll reply with what I found.

I have another formula, COUNTIF, with dynamic range that's not working correctly but I'll start another thread for that one.

Thank You!
 
Upvote 0
If from C9 you do Ctrl down arrow does it take you the last row of data?
If so do it again from where you end up & does that take you to row 1,048,576
 
Upvote 0
It does, 1048576.

I don't know if this has any bearing but I'm sure it does. I have a COUNTIF formula that I added the same dynamic range for range. It works fine in my sample worksheet but in the worksheet I need it in, it counts the "22" in the criteria of ,"<"&22.

VBA Code:
=COUNTIF(C1364:G1368,"<"&22)
Returns correct value of 12

Code:
=COUNTIF(OFFSET(C1,COUNTA(C2:C1500),0,-5,5),"<"&22)
Returns incorrect value of 14

It's counting "22" as = value, not less than.

Last 5 rows:

NC5AnalysisSummaryDP2.xlsm
CDEFG
1364514222942
13651624303641
13661920212236
136712161830
1368412313642
DB SUM


Something is janky with the worksheet, one cell in the range or multiple cells but I can't figure out what. I've macros that I run through the data to change Color Fill/Bold/Text Color depending on different criteria but nothing in the macro that adds text.

I've stripped all formatting, though I knew that should have no effect, it didn't. The cells in the data are all General. I copied/multiplied all the data cells with "1". Got no love.
 
Upvote 0
Code:
=SUMPRODUCT(--(MOD(OFFSET(C9,COUNTA(C10:C1500),0,-5,5),2)=1))

The above formula works. I honestly don't know what I was doing wrong that resulted in it not working earlier but after getting some sleep and trying again, it works. The above formula works perfectly as suggested by Fluff.
Sorry Fluff for not being able to make it work earlier.
You were helpful but I was having an idiot day.

I did download the data again and copy/pasted it into the same worksheet and all is well. I just don't know, but it works great now.
 
Upvote 0

Forum statistics

Threads
1,216,082
Messages
6,128,716
Members
449,464
Latest member
againofsoul

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