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

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
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,215,417
Messages
6,124,787
Members
449,188
Latest member
Hoffk036

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