Extract subrange from a range

azer

New Member
Joined
Jan 31, 2013
Messages
2
Hello and thank you for your time and help,

I am trying to create a function which would extract a subset from a given range depending on the values contained in another range. The final aim is to be able to use the Percentrank function on dynamically changeable groups

ABCD
1CountryGPBGroupPercentrank
2Albania50001?
3France280002
4Romania60001
5US340002

<tbody>
</tbody>

The idea would to have something like Percentrank(subset(B2:B4, C2:C4, 1), B2) with the subset function returning the subset as a range.

I have started with something like this but am stuck on a few issues:

Function Subset(x As Range, y As Range, V As String) As Range


Dim z As Range
Dim c As Range


For Each c In x

' I don't see how to refer to the equivalent cell in y:
If ??.Value = Valeur Then


If Not z Is Nothing Then
Set z = Union(z, c)
Else
Set z = c
End If
End If
Next

'Even with a simple example I am unable to return a range:

Subset = z


End Function


Thank you in advance for your help
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Here's my latest try which doesn't work:

Code:
Function Subs(x As Range, y As Range, V As Integer) As Range

Dim z As Range
Dim c As Cell
Dim n As Integer

    For Each c In x.Cells[INDENT]Set n = c.Row[/INDENT]
[INDENT]If y(1, n).Value = Valeur Then[/INDENT]
[INDENT=2]If Not z Is Nothing Then[/INDENT]
[INDENT=3]Set z = Union(z, c)[/INDENT]
[INDENT=2]Else[/INDENT]
[INDENT=3]Set z = c[/INDENT]
[INDENT=2]End If[/INDENT]
[INDENT]End If[/INDENT]
    Next

Subs = z

End Function

Any thoughts?
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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