Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default Odd numbered Range Names ?

I have a macro program aimed at deleting unwanted range names.
The intent is for the program to cycle through each range name until it
finds one meeting my delete criteria, delete it then move on.
Suppose I have 10 range names (eg MyRange_1 thru MyRange_10), all meeting my
delete criteria, to remove.
The macro runs OK, but only selects and deletes EVEN numbered range names.
If I then run the program again, it removes numbers 1, 5 & 9, leaving 3 & 7.
Running again removes 3
Running again removes 7

I use "MyName = Names(X).Name" to cycle through,
where X is from "For X= 1 to 10 Step 1"

I feel there is something I don't understand about how Excel stores range
names.
How can I make my program delete all in one pass?
Any suggestions most welcome.

--
donwb
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Odd numbered Range Names ?

Hi Don,

Try reversing the sequence:

For X= 10 to 1 Step -1
If Your condition = True Then



---
Regards,
Norman



"donbowyer" wrote in message
...
I have a macro program aimed at deleting unwanted range names.
The intent is for the program to cycle through each range name until it
finds one meeting my delete criteria, delete it then move on.
Suppose I have 10 range names (eg MyRange_1 thru MyRange_10), all meeting
my
delete criteria, to remove.
The macro runs OK, but only selects and deletes EVEN numbered range names.
If I then run the program again, it removes numbers 1, 5 & 9, leaving 3 &
7.
Running again removes 3
Running again removes 7

I use "MyName = Names(X).Name" to cycle through,
where X is from "For X= 1 to 10 Step 1"

I feel there is something I don't understand about how Excel stores range
names.
How can I make my program delete all in one pass?
Any suggestions most welcome.

--
donwb



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Odd numbered Range Names ?

Hi,

You have to delete in reverse order:

Sub DeleteRanges()


For i = Names.Count To 1 Step -1
If Left(Names(i).Name, 7) = "MyRange" Then <===== Change as required
Names(i).Delete
End If

Next i
End Sub


HTH

"donbowyer" wrote:

I have a macro program aimed at deleting unwanted range names.
The intent is for the program to cycle through each range name until it
finds one meeting my delete criteria, delete it then move on.
Suppose I have 10 range names (eg MyRange_1 thru MyRange_10), all meeting my
delete criteria, to remove.
The macro runs OK, but only selects and deletes EVEN numbered range names.
If I then run the program again, it removes numbers 1, 5 & 9, leaving 3 & 7.
Running again removes 3
Running again removes 7

I use "MyName = Names(X).Name" to cycle through,
where X is from "For X= 1 to 10 Step 1"

I feel there is something I don't understand about how Excel stores range
names.
How can I make my program delete all in one pass?
Any suggestions most welcome.

--
donwb

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default Odd numbered Range Names ?

Thanks Norman & Toppers
I reversed the sequence & used T's snippet of code. It works fine.
--
donwb


"Toppers" wrote:

Hi,

You have to delete in reverse order:

Sub DeleteRanges()


For i = Names.Count To 1 Step -1
If Left(Names(i).Name, 7) = "MyRange" Then <===== Change as required
Names(i).Delete
End If

Next i
End Sub


HTH

"donbowyer" wrote:

I have a macro program aimed at deleting unwanted range names.
The intent is for the program to cycle through each range name until it
finds one meeting my delete criteria, delete it then move on.
Suppose I have 10 range names (eg MyRange_1 thru MyRange_10), all meeting my
delete criteria, to remove.
The macro runs OK, but only selects and deletes EVEN numbered range names.
If I then run the program again, it removes numbers 1, 5 & 9, leaving 3 & 7.
Running again removes 3
Running again removes 7

I use "MyName = Names(X).Name" to cycle through,
where X is from "For X= 1 to 10 Step 1"

I feel there is something I don't understand about how Excel stores range
names.
How can I make my program delete all in one pass?
Any suggestions most welcome.

--
donwb

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
converting email address names in a range of cells to real names John Excel Worksheet Functions 1 May 19th 10 03:44 PM
COPYING FORMULA CONTAINING NAMES/RELATIVE RANGE NAMES Bricol Excel Discussion (Misc queries) 0 July 8th 08 03:54 PM
count even-numbered values in a range Dave F[_2_] Excel Discussion (Misc queries) 5 August 1st 07 04:12 PM
create numbered sortable numbered list in excel coloradio Excel Discussion (Misc queries) 2 November 15th 06 06:50 PM
Selecting range in list of range names depending on a cell informa Courreges Excel Discussion (Misc queries) 2 June 19th 06 10:59 AM


All times are GMT +1. The time now is 02:39 PM.

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

About Us

"It's about Microsoft Excel"