Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Iterate through Names for text

I need to search through the Named Ranges in a sheet and for the ones
that contain certain text, in this case "IMP" then I need to set a
conditonal format to the range. I have the conditonal formating part
working but Im having trouble iterating through the names for the text

My code is

Dim zNmRng

For Each zNmRng In ActiveSheet.Names ' Iterate through names.
If zNmRng = Cells.Find(what:="IMP", After:=ActiveCell,
LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False) Then

'Conditional formating code goes here

End If
Next

I am obviously using the find method incorrectly


I also want to have a second condition if, the first conditon is true
then I need to see if the name has "ID" in the name and if so skip
the code. Im sure that once I figure out how to do the first part, the
second is just a mater of nesting.

Here are some examples of the named ranges:

IMP_100_Hz ---- do
LC_100_Hz ------ Skip
IMP_ID ------------ Skip
IMP_20K_Hz ---- do

Any help will be appreciated
Robert

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default Iterate through Names for text

Hi Robert,

If "IMP_" is always going to be at the left of the string and "_ID" at
the right then you could do away with the Find methos altogether and
just use the Left() and Right() functions. If not then perhaps you can
use the Mid() function.

For the second condition you could use a nested If statement or simply
use an AND statement in the first If statement.

Let me know if you can't work it out.

NickH


wrote:
I need to search through the Named Ranges in a sheet and for the ones
that contain certain text, in this case "IMP" then I need to set a
conditonal format to the range. I have the conditonal formating part
working but Im having trouble iterating through the names for the text

My code is

Dim zNmRng

For Each zNmRng In ActiveSheet.Names ' Iterate through names.
If zNmRng = Cells.Find(what:="IMP", After:=ActiveCell,
LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False) Then

'Conditional formating code goes here

End If
Next

I am obviously using the find method incorrectly


I also want to have a second condition if, the first conditon is true
then I need to see if the name has "ID" in the name and if so skip
the code. Im sure that once I figure out how to do the first part, the
second is just a mater of nesting.

Here are some examples of the named ranges:

IMP_100_Hz ---- do
LC_100_Hz ------ Skip
IMP_ID ------------ Skip
IMP_20K_Hz ---- do

Any help will be appreciated
Robert


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Iterate through Names for text

Nick, I ended up working the Toms sugestion. However, I would like to
see you would use the Left() Right() and Mid functions in this case, if
you have time... I will certainly want to learn to use them.

Thanks
Robert



NickH wrote:
Hi Robert,

If "IMP_" is always going to be at the left of the string and "_ID" at
the right then you could do away with the Find methos altogether and
just use the Left() and Right() functions. If not then perhaps you can
use the Mid() function.

For the second condition you could use a nested If statement or simply
use an AND statement in the first If statement.

Let me know if you can't work it out.

NickH


wrote:
I need to search through the Named Ranges in a sheet and for the ones
that contain certain text, in this case "IMP" then I need to set a
conditonal format to the range. I have the conditonal formating part
working but Im having trouble iterating through the names for the text

My code is

Dim zNmRng

For Each zNmRng In ActiveSheet.Names ' Iterate through names.
If zNmRng = Cells.Find(what:="IMP", After:=ActiveCell,
LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False) Then

'Conditional formating code goes here

End If
Next

I am obviously using the find method incorrectly


I also want to have a second condition if, the first conditon is true
then I need to see if the name has "ID" in the name and if so skip
the code. Im sure that once I figure out how to do the first part, the
second is just a mater of nesting.

Here are some examples of the named ranges:

IMP_100_Hz ---- do
LC_100_Hz ------ Skip
IMP_ID ------------ Skip
IMP_20K_Hz ---- do

Any help will be appreciated
Robert


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
Iterate through a form RobEdgeler Excel Programming 2 September 17th 05 06:58 PM
Iterate through controls lgbjr Excel Programming 3 May 28th 05 02:09 PM
How to iterate through all Text Boxes on a Form? Ed Excel Programming 5 February 16th 05 01:24 PM
Can't iterate thru a row with For peter Excel Programming 2 January 7th 05 04:46 AM
Iterate columns wired Excel Programming 9 November 14th 03 11:14 PM


All times are GMT +1. The time now is 06:43 AM.

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"