noncontiguous range, minimal row...

hurgadion

Active Member
Joined
Mar 19, 2010
Messages
426
Hi,
is it a simple Way to find a minimal row of a noncontiguous Range (number of Areas may be unknown... but we have function AREAS()) using a Formula ??

for (B4:B7,E2:E15,G6:G10,I3:I20) result is 2...

best regards,
hurgadion
 
Last edited:
Yes... The above formula returns minimal row of first Area... It's a little problem with function INDEX in array Formula approach, I think...
 
Last edited:
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Does that work for you? It returns 4 for me, rather than 2.
Same for me, it returned 4 instead of 2.
 
Upvote 0
In all my experiments, INDEX returns a #VALUE! error if you pass an array as the AREAS argument.
 
Upvote 0
maybe this array construction may be useful ? I don't know...
Code:
=MIN(INDEX(A1:A10,N(IF(1,{1;3;5}))))
 
Upvote 0
Code:
Function FindMinRow(myRange As Range) As Long

    Dim cell As Range
    Dim minRow As Long
  
'   Originally set minRow to be last row on sheet
    minRow = Rows.Count
    
'   Loop through all ranges
    For Each cell In myRange
        If cell.Row < minRow Then minRow = cell.Row
    Next cell
    
    FindMinRow = minRow
    
End Function
It would be a little more efficient to iterate each area rather than each cell. Also, you can use the function name like a variable directly within the function instead of creating/using your minRow dummy variable.
Code:
Function GetMinRow(Rng As Range) As Long
  Dim Ar As Range
  GetMinRow = Rows.Count
  For Each Ar In Rng.Areas
    If Ar.Row < GetMinRow Then GetMinRow = Ar.Row
  Next
End Function
 
Last edited:
Upvote 0
You might also add a line to exit the loop if GetMinRow = 1.
 
Upvote 0
Hi

You can use the rectangular range that envelops them:

Code:
=MIN(ROW((B4:B7):(E2:E15):(G6:G10):(I3:I20)))

Remarks:
- for the Max() we need to CSE. Maybe we should use it also for the Min?
- the parentheses are not really needed.
 
Last edited:
Upvote 0
OK,
thank You... is it possible to repeat the above result for a named Range using only this name or a function AREAS() ?

What is CSE ?

How from string "A1:A2;P1:P2" obtain a object A1:A2:P1:P2... ? a function INDIRECT not works, I think...

Best regards...
 
Last edited:
Upvote 0
You can use the rectangular range that envelops them:

Code:
=MIN(ROW((B4:B7):(E2:E15):(G6:G10):(I3:I20)))
Neat! I have never seen a set of three or more colon delimited chained ranges like that before. Not sure how to translate that to a non-contiguous Defined Name range in a formula, but it does make the UDF (user defined function) simpler, that is for sure...
Code:
Function GetMinRow(Rng As Range) As Long
  GetMinRow = Range(Replace(Rng.Address, ",", ":")).Row
End Function
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,957
Messages
6,122,472
Members
449,087
Latest member
RExcelSearch

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