Non-contiguous named range

J

JoeMNY

I have a range (SOURCE) that consists of non-contiguous cells in a column
(eg. ='Log Sheet'!$O$61:$O$110,'Log Sheet'!$O$125:$O$174,'Log
Sheet'!$O$189:$O$238,'Log Sheet'!$O$253:$O$302,'Log Sheet'!$O$317:$O$366,'Log
Sheet'!$O$381:$O$430). When I use the range in a formula
(=COUNTIF(SOURCE,"<>ABCD") it returns the #VALUE error. What am I doing
wrong?

TIA
Joe
 
G

Gary''s Student

Not your problem. COUNTIF works on contiguous ranges only.

The usual workaround is to add up the contiguous pieces:

=COUNTIF() + COUNTIF() + etc.
 
G

Gary''s Student

Sub iamthecount()
For Each r In Range("SOURCE")
If r.Value <> "ABCD" Then
i = i + 1
End If
Next
MsgBox (i)
End Sub

will count the cells that do not equal ABCD
 
J

JoeMNY

Thanks again. That works.

Gary''s Student said:
Sub iamthecount()
For Each r In Range("SOURCE")
If r.Value <> "ABCD" Then
i = i + 1
End If
Next
MsgBox (i)
End Sub

will count the cells that do not equal ABCD
 
P

Peo Sjoblom

There are a couple of other ways to skin this cat

you can use this


=SUM(COUNTIF(INDIRECT({"'Log Sheet'!$O$61:$O$110","'Log
Sheet'!$O$125:$O$174","'Log Sheet'!$O$189:$O$238","'Log
Sheet'!$O$253:$O$302","'Log Sheet'!$O$317:$O$366","'Log
Sheet'!$O$381:$O$430"}),"<>ABCD"))



or since you have a system where your data intervals are the same, 50 cells
then a gap of 14 cell then another 50 you can use the whole range


=SUMPRODUCT(--((MOD(ROW('Log Sheet'!$O$61:$O$430),64)<47)+(MOD(ROW('Log
Sheet'!$O$61:$O$430),65)>60)>0),--('Log Sheet'!$O$61:$O$430<>"ABCD"))


and if you call the full range 'Log Sheet'!$O$61:$O$430 for SOURCE you can
use


=SUMPRODUCT(--((MOD(ROW(SOURCE),64)<47)+(MOD(ROW(SOURCE),65)>60)>0),--(SOURCE<>"ABCD"))




--


Regards,


Peo Sjoblom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top