Using offset in an array function

RossLarson

New Member
Joined
Nov 10, 2012
Messages
4
My data is laid out in a large grid (194R X 50C)

E6:BB6 is top row and
E199:BB199 is bottom row.

I want to check if some element is in each row of the grid and create an arrray of 1s and 0s. This is to multiply with another array of 1s and 0s that I already have so I can sum up the result.

However, the followign piece is giving my #VALUE errors when I evaluate the formula

Code:
OFFSET(Part1!E5:BB5,ROW(1:194),0,1,50)

this causes the surround match and if statements to return a #N/A error

Code:
IF(MATCH(C5,OFFSET(Part1!E5:BB5,ROW(1:194),0,1,50),0) > 0, 1, 0)

Which makes the whole function return #N/A

Code:
=SUMPRODUCT(IF(MATCH(C5,OFFSET(Part1!E5:BB5,ROW(1:194),0,1,50),0) > 0, 1, 0), IF(Part1!$B$6:$B$199=1,1,0))

(obviously this is entered with Ctrl + Shift + Enter)

Any ideas on why the offset is erroring out?

Any help is much appreciated.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Maybe this can work....

=SUMPRODUCT(--(MMULT(--(Part1!$E$5:$BB$199=C5),ROW(Part1!$A$1:$A$50)^0)>0),Part1!$B$5:$B$199)

confirmed with just Enter

M.
 
Upvote 0
Reviewing your post i noticed that data begin at row 6. So the formula needs a small correction

=SUMPRODUCT(--(MMULT(--(Part1!$E$6:$BB$199=C5),ROW(Part1!$A$1:$A$50)^0)>0),Part1!$B$6:$B$199)

By the way, i think this other formula can also work
=SUMPRODUCT(--(COUNTIF(OFFSET(Part1!$E$6:$BB$6,ROW(Part1!$E$6:$BB$199)-ROW(Part1!$E$6),0,1),C5)>0),Part1!$B$6:$B$199)

M.
 
Upvote 0
Marcelo,

Thank you very much, that second formula was perfect!

I appreciate your help.

As far as learning goes, can you explain the use of the --?

Thanks again,
Ross
 
Upvote 0
Marcelo,

Thank you very much, that second formula was perfect!

I appreciate your help.

As far as learning goes, can you explain the use of the --?

Thanks again,
Ross

You are very welcome and thanks for the feedback!

COUNTIF(OFFSET(Part1!$E$6:$BB$6,ROW(Part1!$E$6:$BB$199)-ROW(Part1!$E$6),0,1),C5)>0
returns an array of logical values either True or False, ie, something like
{TRUE;FALSE;FALSE;FALSE;TRUE.......}

-- coerces (converts) True/False to, respectively, 1 or 0 so the SUMPRODUCT can use them in aritmethic operations.

For a very good explanation about SUMPRODUCT take a look at
http://xldynamic.com/source/xld.SUMPRODUCT.html

M.
ps: BTW, the first formula also worked for me and i think it's better/faster
 
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,796
Members
449,095
Latest member
m_smith_solihull

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