Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Finding a text value in a range

I have a section in a procedure where I have put in words what I am trying to do. I have
a named range of unique text entries in a single column, about 16 values. What I am
trying to do is identify if any of the range of cells being looped as below have any of
the values in that range and then act acoordingly. I know I could probably use a hole
range of case arguments but it seemsa sledgehammer to crack a nut. Is there a VBA function
that can do this? I appreciate any help

Set rng = Range("A15:A30")
For n = 1 To 200
If (Cells(n, 18).value (is equal to any of the text values in rng ) Then
Statements etc

Kind Regards,
Graham
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Finding a text value in a range

You could use code something like this...

Dim N As Long
Dim C As Range
Dim Rng As Range
Dim FirstAddress As String

Set Rng = Range("A15:A30")

With Rng
For N = 1 To 200
Set C = .Find(Cells(N, 18), LookIn:=xlValues)
If Not C Is Nothing Then
FirstAddress = C.Address
Do
'
' YOUR STATEMENTS GO HERE
'
Set C = .FindNext(C)
Loop While Not C Is Nothing And C.Address < FirstAddress
End If
Next
End With

Rick


"Graham" wrote in message
...
I have a section in a procedure where I have put in words what I am
trying to do. I have a named range of unique text entries in a single
column, about 16 values. What I am trying to do is identify if any of the
range of cells being looped as below have any of the values in that range
and then act acoordingly. I know I could probably use a hole range of case
arguments but it seemsa sledgehammer to crack a nut. Is there a VBA
function that can do this? I appreciate any help

Set rng = Range("A15:A30")
For n = 1 To 200
If (Cells(n, 18).value (is equal to any of the text values in rng ) Then
Statements etc

Kind Regards,
Graham


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Finding a text value in a range

Many thanks for that Rick, I just couldn't get my head round it. Your help is much
appreciated.

Graham

Rick Rothstein (MVP - VB) wrote:
You could use code something like this...

Dim N As Long
Dim C As Range
Dim Rng As Range
Dim FirstAddress As String

Set Rng = Range("A15:A30")

With Rng
For N = 1 To 200
Set C = .Find(Cells(N, 18), LookIn:=xlValues)
If Not C Is Nothing Then
FirstAddress = C.Address
Do
'
' YOUR STATEMENTS GO HERE
'
Set C = .FindNext(C)
Loop While Not C Is Nothing And C.Address < FirstAddress
End If
Next
End With

Rick


"Graham" wrote in message
...
I have a section in a procedure where I have put in words what I am
trying to do. I have a named range of unique text entries in a single
column, about 16 values. What I am trying to do is identify if any of
the range of cells being looped as below have any of the values in
that range and then act acoordingly. I know I could probably use a
hole range of case arguments but it seemsa sledgehammer to crack a
nut. Is there a VBA function that can do this? I appreciate any help

Set rng = Range("A15:A30")
For n = 1 To 200
If (Cells(n, 18).value (is equal to any of the text values in rng ) Then
Statements etc

Kind Regards,
Graham


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
Finding text in a range Always need help asap :-) Excel Discussion (Misc queries) 5 October 1st 08 08:09 PM
Finding text or part of a text inside the value cell [email protected] Excel Programming 1 November 23rd 07 06:19 PM
Finding text in a cell and returning a value based on that text [email protected] Excel Discussion (Misc queries) 5 January 10th 07 06:01 PM
Functions- Finding and counting specified text in cell range holliedavis Excel Worksheet Functions 8 November 22nd 06 05:49 PM
Finding the Excat text in a range schoujar Excel Programming 2 August 26th 05 06:46 AM


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

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"