VBA Select range using Find method and variables

Giggs1991

Board Regular
Joined
Mar 17, 2019
Messages
50
Hi All,

I have a set of values in Column A of a worksheet named "Data".
Cell A1 has the value as "Description"
Cell A9 is blank
Cell A10 has the value as "Team Total"
The current active cell is D100
I would like to use the VBA "Cells.Find(What:="Description" statement to get to A1 from D100. Store the address of cell A1 in a variable named rng1. Then use the VBA "Cells.Find(What:="Team Total" statement to get to A10 from A1. Store the address of A10 in a variable called rng2. Next I would like to select the range A1 to A10 using a statement like =Range(rng1:rng2).
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
I don't understand your goal, but if worksheet "Data" has no more cells with "Description" and "Team Total", it should work:
VBA Code:
Sub giggs()
Dim rng1 As Range, rng2 As Range, sh As Worksheet
    Set sh = ActiveWorkbook.Sheets("Data")
    Set rng1 = sh.UsedRange.Find("Description", , xlValues)
    Set rng2 = sh.UsedRange.Find("Team Total", , xlValues)
    
    sh.Range(rng1, rng2).Select
End Sub
 
Upvote 0
I don't understand your goal, but if worksheet "Data" has no more cells with "Description" and "Team Total", it should work:
VBA Code:
Sub giggs()
Dim rng1 As Range, rng2 As Range, sh As Worksheet
    Set sh = ActiveWorkbook.Sheets("Data")
    Set rng1 = sh.UsedRange.Find("Description", , xlValues)
    Set rng2 = sh.UsedRange.Find("Team Total", , xlValues)
  
    sh.Range(rng1, rng2).Select
End Sub
Thank you...it works
 
Upvote 0
Default property of rng1 (rng1 is a variable with type range) is value, if you need an address, use rng1.address
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,334
Members
449,077
Latest member
Jocksteriom

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