Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default Find a string match in a column

Hi,

I am wanting to find a string from a column which matches my variable. I
modified this code of Tom Ogilvy's in a related answer

For Each cell In rngA
res = Application.Match("*" & cell.Value & "*", rngB, 0)
If Not IsError(res) Then
Set rng = rngB(res)
rng.Offset(0, 1).Value = cell
End If

to

For Each cell In rngA
res = Application.Match(myVar, MyRng)
If Not IsError(res) Then
myCode
End If
next

but I get a number in res that in fact is a blank cell. Can't work out what
is happening. Any help appreciated.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Find a string match in a column

You omitted the third argument in the function.
Add comma, zero after MyRng
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"Matilda"

wrote in message
Hi,
I am wanting to find a string from a column which matches my variable. I
modified this code of Tom Ogilvy's in a related answer

For Each cell In rngA
res = Application.Match("*" & cell.Value & "*", rngB, 0)
If Not IsError(res) Then
Set rng = rngB(res)
rng.Offset(0, 1).Value = cell
End If

to

For Each cell In rngA
res = Application.Match(myVar, MyRng)
If Not IsError(res) Then
myCode
End If
next

but I get a number in res that in fact is a blank cell. Can't work out what
is happening. Any help appreciated.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Find a string match in a column

Try using

res = Application.Match(myVar, MyRng,0)


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Matilda" wrote in message
...
Hi,

I am wanting to find a string from a column which matches my variable. I
modified this code of Tom Ogilvy's in a related answer

For Each cell In rngA
res = Application.Match("*" & cell.Value & "*", rngB, 0)
If Not IsError(res) Then
Set rng = rngB(res)
rng.Offset(0, 1).Value = cell
End If

to

For Each cell In rngA
res = Application.Match(myVar, MyRng)
If Not IsError(res) Then
myCode
End If
next

but I get a number in res that in fact is a blank cell. Can't work out

what
is happening. Any help appreciated.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default Find a string match in a column

Hi Jim,

I tried that, but get a type mismatch error. I'm obviously on the wrong
wavelength here. I assumed that Match would return a number (row number) if
the cell being examined contained a string maatching the variable. The column
being searched contains strings, not dates or numbers, so can't work out what
is happening.

Many thanks

"Jim Cone" wrote:

You omitted the third argument in the function.
Add comma, zero after MyRng
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"Matilda"

wrote in message
Hi,
I am wanting to find a string from a column which matches my variable. I
modified this code of Tom Ogilvy's in a related answer

For Each cell In rngA
res = Application.Match("*" & cell.Value & "*", rngB, 0)
If Not IsError(res) Then
Set rng = rngB(res)
rng.Offset(0, 1).Value = cell
End If

to

For Each cell In rngA
res = Application.Match(myVar, MyRng)
If Not IsError(res) Then
myCode
End If
next

but I get a number in res that in fact is a blank cell. Can't work out what
is happening. Any help appreciated.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Find a string match in a column

res should be declared as a Variant.
--
Jim Cone
San Francisco, USA
http://www.officeletter.com/blink/specialsort.html

"Matilda"

wrote in message
Hi Jim,
I tried that, but get a type mismatch error. I'm obviously on the wrong
wavelength here. I assumed that Match would return a number (row number) if
the cell being examined contained a string maatching the variable. The column
being searched contains strings, not dates or numbers, so can't work out what
is happening.
Many thanks

"Jim Cone" wrote:

You omitted the third argument in the function.
Add comma, zero after MyRng
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default Find a string match in a column

aaaaahhhhhh !!!! Thanks Bob, and Jim. Variant type ... sorted!



"Bob Phillips" wrote:

Try using

res = Application.Match(myVar, MyRng,0)


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Matilda" wrote in message
...
Hi,

I am wanting to find a string from a column which matches my variable. I
modified this code of Tom Ogilvy's in a related answer

For Each cell In rngA
res = Application.Match("*" & cell.Value & "*", rngB, 0)
If Not IsError(res) Then
Set rng = rngB(res)
rng.Offset(0, 1).Value = cell
End If

to

For Each cell In rngA
res = Application.Match(myVar, MyRng)
If Not IsError(res) Then
myCode
End If
next

but I get a number in res that in fact is a blank cell. Can't work out

what
is happening. Any help appreciated.




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
Vlookup to find a match in a string KCK Excel Worksheet Functions 6 March 16th 09 07:59 PM
How to find last match in a column? [email protected] Excel Discussion (Misc queries) 5 October 12th 08 12:55 PM
Find a string within a column Rookie_User Excel Discussion (Misc queries) 8 March 17th 06 02:12 PM
Find text string in column? Dave Peterson Excel Discussion (Misc queries) 3 August 26th 05 01:22 AM
Trying to find string in a column or row strataguru[_12_] Excel Programming 1 December 24th 03 01:02 AM


All times are GMT +1. The time now is 10:22 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"