Is there a way to count/sum a Named Range which is not contiguous?

pvr928

Well-known Member
Joined
Oct 21, 2002
Messages
790
Hi

I have a Named Range, being:

Code:
TEST_Range =TEST!$D$3:$D$9,TEST!$D$14:$D$22

Although I can treat this as a contiguous range within VBA, I am yet to find a worksheet way to do the same. For example:

Code:
=ROWS(Test_Range)


returns a '#REF!' error.

Sure, I can split up the range into a series of contiguous ranges and then aggregate them, but this would then defeat the purpose of having a single, non-contiguous, range.

Any help greatly appreciated.

Cheers

pvr928
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Not all functions admit non-contiguous ranges, so ROWS() is one of them. Aggregation functions like SUM(), AVERAGE(), MAX() and so on will succeed.
 
Upvote 0
Yes - perhaps someone smarter than myself can do something with a worksheet function.

It is pretty simple - the user is required to ensure all cells in the non-contiguous range are populated with text (this is done via a worksheet change event opening a UserForm whenever the non-contiguous range is selected). All I want is something to check whether all the cells are populated, something like:

Code:
If ( Count of Rows of Non-Contiguous Range = Count of Cells of Non-Contiguous Range Containing Text ) Then "Ok" Else "Check" )

Cheers

pvr928
 
Upvote 0
Add the following function to your workbook if you will...

Function ArrayUnion(ParamArray Arg() As Variant) As Variant
' Code: Juan Pablo González
' Spec: Aladin Akyurek
' May 4, 2003
' Ref: TinyURL.com - shorten that long URL into a tiny URL
Dim TempUnion() As Variant
Dim i As Long, Itm As Variant, Ctr As Long
For i = LBound(Arg) To UBound(Arg)
Arg(i) = Arg(i)
If IsArray(Arg(i)) Then
For Each Itm In Arg(i)
Ctr = Ctr + 1
ReDim Preserve TempUnion(1 To Ctr) As Variant
TempUnion(Ctr) = Itm
Next Itm
Else
Ctr = Ctr + 1
ReDim Preserve TempUnion(1 To Ctr) As Variant
TempUnion(Ctr) = Arg(i)
End If
Next i
ArrayUnion = TempUnion
End Function

Redefine TEST_Range as:

=ARRAYUNION(Test!$D$3:$D$9,Test!$D$14:$D$22)

This...

If ( Count of Rows of Non-Contiguous Range = Count of Cells of Non-Contiguous Range Containing Text ) Then "Ok" Else "Check" )

becomes:

=IF(SUMPRODUCT(ISTEXT(Test_Range)+0)=COLUMNS(Test_Range),"ok","check")
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,383
Members
448,956
Latest member
JPav

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