Hi, I'm trying to find the row number of the cell that has the value 22 in a dynamic non contiguous range that i have stored in cell J18 using the Match function.
I would also like to find the 4th largest number is the in range using the Large Function.
I had found on a forum that a function could be added using VBA to convert a non contiguous range to a contiguous range.
The code for that function is :
Function Arrange(rng As Range) As Variant
Dim temp As Variant
Dim i As Long
Dim r As Range
ReDim temp(1 To rng.Cells.Count)
i = 1
For Each r In rng
temp(i) = r.Value
i = i + 1
Next r
Arrange = Application.Transpose(temp)
End Function
This was giving me some issues though since what I had in cell J18 is a text so I found another function that converts the text to a range :
Function TXT2RNG(text) As Variant
Set TXT2RNG = Range(text)
End Function
I then tried to combine these together to achieve my goal.
In cell J18 I have Sheet1!E71:E94,Sheet1!E181:E201
When i try =Arrange(Sheet1!E71:E94,Sheet1!E181:E201)
I get a #Value error.
When i try
=Arrange((Sheet1!E71:E94,Sheet1!E181:E201))
It works without error
When i try
=Arrange(J18)
it just returns the text Sheet1!E71:E94,Sheet1!E181:E201
When i try
=Arrange(TXT2RNG(J18))
It works without error
Now when i try
=LARGE(Arrange((Sheet1!E71:E94,Sheet1!E181:E201)),4)
and also
=MATCH(22,Arrange((Sheet1!E71:E94,Sheet1!E181:E201)), 0)
They work
But if I try using the cell reference J18 instead of directly inputting Sheet1!E71:E94,Sheet1!E181:E201
It doesn't work, even if try including the TXT2RNG function.
I would also like to find the 4th largest number is the in range using the Large Function.
I had found on a forum that a function could be added using VBA to convert a non contiguous range to a contiguous range.
The code for that function is :
Function Arrange(rng As Range) As Variant
Dim temp As Variant
Dim i As Long
Dim r As Range
ReDim temp(1 To rng.Cells.Count)
i = 1
For Each r In rng
temp(i) = r.Value
i = i + 1
Next r
Arrange = Application.Transpose(temp)
End Function
This was giving me some issues though since what I had in cell J18 is a text so I found another function that converts the text to a range :
Function TXT2RNG(text) As Variant
Set TXT2RNG = Range(text)
End Function
I then tried to combine these together to achieve my goal.
In cell J18 I have Sheet1!E71:E94,Sheet1!E181:E201
When i try =Arrange(Sheet1!E71:E94,Sheet1!E181:E201)
I get a #Value error.
When i try
=Arrange((Sheet1!E71:E94,Sheet1!E181:E201))
It works without error
When i try
=Arrange(J18)
it just returns the text Sheet1!E71:E94,Sheet1!E181:E201
When i try
=Arrange(TXT2RNG(J18))
It works without error
Now when i try
=LARGE(Arrange((Sheet1!E71:E94,Sheet1!E181:E201)),4)
and also
=MATCH(22,Arrange((Sheet1!E71:E94,Sheet1!E181:E201)), 0)
They work
But if I try using the cell reference J18 instead of directly inputting Sheet1!E71:E94,Sheet1!E181:E201
It doesn't work, even if try including the TXT2RNG function.