.find inside a ranges union

Maryca

New Member
Joined
Mar 25, 2013
Messages
2
Hi!

I have a problem with the function .find.

Excel starts the debug when I need to find the value "minRow" inside "myRange" that is the union of two different ranges.

I don't know why, can someone help me?

thanks!


Set myRange1 = Worksheets("CAST SEGMENTS half day").Range("K2:P2")
Set myRange2 = Worksheets("CAST SEGMENTS half day").Range("R2:S2")

myRange = Application.Union(myRange1, myRange2)

minRow = Application.WorksheetFunction.Min(myRange)


Set rng = Range("myRange").find(What:=minRow, LookAt:=xlWhole, lookin:=xlValues)
num_colonna = rng.Column
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Hi and welcome to the board.

Try something like this...

Code:
    [COLOR=darkblue]Dim[/COLOR] myRange [COLOR=darkblue]As[/COLOR] Range, rng [COLOR=darkblue]As[/COLOR] Range, minRow [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Single[/COLOR], num_colonna [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Long[/COLOR]
    
    [COLOR=#ff0000]Set myRange[/COLOR] = Worksheets("CAST SEGMENTS half day").Range("K2:P2,R2:S2")
    minRow = Application.WorksheetFunction.Min(myRange)
    
    [COLOR=darkblue]Set[/COLOR] rng = [COLOR=#ff0000]myRange[/COLOR].Find(What:=minRow, LookAt:=xlWhole, LookIn:=xlValues)
    num_colonna = rng.Column
 
Upvote 0
Thanks for answering.

There are still problems, excel is saying "Duplicate declaration in current scope".
 
Upvote 0
...excel is saying "Duplicate declaration in current scope".
That means you already have Dim'med one or more of the variables AlphaFrog included in his Dim statement... just remove the duplicated ones so only each variable is Dim'med only once within your Sub.
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,022
Members
448,939
Latest member
Leon Leenders

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