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:
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

This should work amazingly!! Thank you!

could i say "activerange.name=rangex " to name it?
 
Upvote 0

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
thank you rick! how do i now name the range?

Once you have selected the range, you can execute this line of code to name that selection...

Code:
Selection.Name = "TheNameYouWantToGiveThisRange"
However, if that is your ultimate goal (only to name the range), then you do not need to select the range first as you can name it directly (very seldom is it necessary to select a range before you do something with it).

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).Name = "TheNameYouWantToGiveThisRange
 
Upvote 0
Once you have selected the range, you can execute this line of code to name that selection...

Code:
Selection.Name = "TheNameYouWantToGiveThisRange"
However, if that is your ultimate goal (only to name the range), then you do not need to select the range first as you can name it directly (very seldom is it necessary to select a range before you do something with it).

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).Name = "TheNameYouWantToGiveThisRange
excellent. Thank you sir.
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,806
Members
449,048
Latest member
greyangel23

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