code needed to establish a dynamic range in active worksheet, starting at a1 and extending n number of cols, and n number of rows

jdahlke

Board Regular
Joined
Jul 16, 2012
Messages
59
needs to cover a1 through the bottom right cell with a value in it. just like hitting end home.
I need a simple code for this, I've researched online and can't find anything simple. Need to name the range "rangex"




Thank you!
 
Last edited:

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Try this:

Code:
Sub findrange()
    Dim rangex As Range
    Set rangex = ThisWorkbook.ActiveSheet.UsedRange
    rangex.Select
End Sub
 
Upvote 0
Unfortunately, the UsedRange suggestion of Mindpsyche may not always work correctly... UsedRange can, under certain circumstances, end up "remembering" cells that are no longer "in use". You may find this mini-blog article (and the subsequent discussion that followed from it) of interest...

Replacement for the Flawed UsedRange Property
 
Upvote 0
thank you, but it should only select the values that would be selected if you do the following:
click on a1, hold shift, and key end home.
 
Upvote 0
Thanks Rick, im still very new to vba so any feedback on my code is much appreciated, and i will have a look at that link :)
 
Upvote 0
Just tried that and it did exactly the same thing, not exactly sure what you want. Post some data if you can please.
 
Upvote 0
hey mindpsyche, thanks for your help, but unfortunately the code given came up with an error when run.
 
Last edited:
Upvote 0
this is frustrating, cannot find a simple code to establish this range.

Using parts of the code I posted in the mini-blog article I referred you to, this single (albeit long) line of code will do what you asked for...
Code:
Range("A1:" & Cells(Cells.Find(What:="*", SearchOrder:=xlRows, _
      SearchDirection:=xlPrevious, LookIn:=xlFormulas).Row, _
      Cells.Find(What:="*", SearchOrder:=xlByColumns, _
      SearchDirection:=xlPrevious, LookIn:=xlFormulas).Column).Address).Select
 
Upvote 0
What's the error? Once again, a more clearer explanation of how your sheet is set up and which range you need to be identified will enable more knowledgeable posters to help you.
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,397
Members
448,957
Latest member
Hat4Life

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