Named Range Macro

RoyinUK2000

Board Regular
Joined
Mar 26, 2002
Messages
79
I have tried to make a macro that will look if any data has been added to a worksheet and make the whole data selection a named range, but a novice like me cannot get this to work.

My code is as follows:-
Sub NameRange()
Range("A1").Select
Selection.End(xlToRight).Select
addy1 = Selection.Address(ReferenceStyle:=xlR1C1)
Selection.End(xlDown).Select
addy2 = Selection.Address(ReferenceStyle:=xlR1C1)
ActiveWorkbook.Names.add Name:="Range1", RefersToR1C1:="=Drumming Details!" & addy1 & ":" & addy2
End Sub


Anyone help a newbie out here would be most appreciated.


Ta
Roy
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hi Roy,

How about just referring to the usedrange?

<pre>
Sub NameRange()
Dim addy1 As Range
Set addy1 = ThisWorkbook.Sheets(1).UsedRange
ThisWorkbook.Names.Add Name:="Range1", RefersTo:=addy1
End Sub

</pre>

HTH
 
Upvote 0
Try this:

Code:
Sub NameThatRange()
    Sheets("Drumming Details").Range("A1").CurrentRegion.Name = "Range1"
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,611
Messages
6,120,509
Members
448,967
Latest member
screechyboy79

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