Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default deleting named ranges on a worksheet (not workbook)

Hi All
I am writhing a routine that takes a data set that is pasted in and
then does several calculations. in the process it defines several
ranges. I would like to have a line of code (or subroutine)that would
delete any named ranges in the worksheet to make certian we are
starting with clean sheet. Any help is appreciated. Thanks BRC
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 563
Default deleting named ranges on a worksheet (not workbook)

This deletes all names in a workbook

Sub tryme()
Set nms = ActiveWorkbook.Names
Set wks = Worksheets(1)
'MsgBox nms.Count
mylast = nms.Count
For r = mylast To 1 Step -1
' MsgBox nms(r).Name
nms(r).Delete
Next r
End Sub

I have commented out some debugging statements that I used to get it to
work. I had forgotten you must work from the end of a collection when
deleting!
best wishes
--
Bernard Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme

"BRC" wrote in message
...
Hi All
I am writhing a routine that takes a data set that is pasted in and
then does several calculations. in the process it defines several
ranges. I would like to have a line of code (or subroutine)that would
delete any named ranges in the worksheet to make certian we are
starting with clean sheet. Any help is appreciated. Thanks BRC


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default deleting named ranges on a worksheet (not workbook)

Sub delnamesonactivesheet()
sl = Len(ActiveSheet.Name)
For Each n In ActiveWorkbook.Names
If Mid(n, 2, sl) = ActiveSheet.Name Then n.Delete
Next
End Sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"BRC" wrote in message
...
Hi All
I am writhing a routine that takes a data set that is pasted in and
then does several calculations. in the process it defines several
ranges. I would like to have a line of code (or subroutine)that would
delete any named ranges in the worksheet to make certian we are
starting with clean sheet. Any help is appreciated. Thanks BRC


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default deleting named ranges on a worksheet (not workbook)

Give this a try...

Sub DeleteNamesFromActiveSheet()
Dim N As Name
For Each N In ActiveWorkbook.Names
If N.RefersToRange.Parent.Name = ActiveSheet.Name Then N.Delete
Next
End Sub

As constructed, it removes the names from the ActiveSheet, but you can make
the obvious change if you want to remove the names from a specified
worksheet instead of the ActiveSheet.

--
Rick (MVP - Excel)


"BRC" wrote in message
...
Hi All
I am writhing a routine that takes a data set that is pasted in and
then does several calculations. in the process it defines several
ranges. I would like to have a line of code (or subroutine)that would
delete any named ranges in the worksheet to make certian we are
starting with clean sheet. Any help is appreciated. Thanks BRC


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default deleting named ranges on a worksheet (not workbook)

On Jan 9, 2:22*pm, "Rick Rothstein"
wrote:
Give this a try...

Sub DeleteNamesFromActiveSheet()
* Dim N As Name
* For Each N In ActiveWorkbook.Names
* * If N.RefersToRange.Parent.Name = ActiveSheet.Name Then N.Delete
* Next
End Sub

As constructed, it removes the names from the ActiveSheet, but you can make
the obvious change if you want to remove the names from a specified
worksheet instead of the ActiveSheet.

--
Rick (MVP - Excel)

"BRC" wrote in message

...



Hi *All
I am writhing a routine that takes a data set that is pasted in and
then does several calculations. *in the process it defines several
ranges. *I would like to have a line of code (or subroutine)that would
delete any named ranges in the worksheet to make certian we are
starting with clean sheet. *Any help is appreciated. Thanks BRC- Hide quoted text -


- Show quoted text -


Thank you all for the input. I used Don's code and it seems to work
fine. I did have to change the string read from 2 to 3. I am using
excel 2007 and it appears that range names in this version are
preceded by....='.... and the names start at the 3rd character. thanks
again.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default deleting named ranges on a worksheet (not workbook)

Thank you all for the input. I used Don's code and it seems
to work fine. I did have to change the string read from 2 to 3.
I am using excel 2007 and it appears that range names in
this version are preceded by....='.... and the names start at
the 3rd character. thanks again.


Of course, I have no problem with you using one of the other solutions
offered to you; however, I just wanted to point out that the one I posted
requires no string manipulations at all... it simply uses the built in
properties of the the Name object.

--
Rick (MVP - Excel)

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I delete all named ranges in a workbook or worksheet? AZSteve Excel Programming 5 October 21st 09 06:48 PM
Deleting all named ranges that have a workbook scope Babymech Excel Discussion (Misc queries) 3 February 19th 09 04:21 PM
Copy worksheet with named ranges to new workbook and keep names Sandy Excel Worksheet Functions 0 July 11th 08 04:37 PM
Named ranges scope / workbook/worksheet level named ranges- changeswith variable use... christian_spaceman Excel Programming 3 December 24th 07 01:15 PM
named ranges at workbook and worksheet levels mark kubicki Excel Programming 5 September 15th 04 10:46 PM


All times are GMT +1. The time now is 11:41 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"