#1   Report Post  
Posted to microsoft.public.excel.programming
Tom Tom is offline
external usenet poster
 
Posts: 25
Default Caontains.

Hello again,

how can I check it if hole column contains string which I am lookig for.

for example:
mystring = "test2005"
if mystring in column A give me number of this row

thanks tomas


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Caontains.

Hi THomas

One way, returns 0 for no match:

Sub test()
MsgBox FoundRow(Range("A:A"), "test2005")
End Sub

Function FoundRow(Rng As Range, Txt As String) As Long
On Error Resume Next
FoundRow = Rng.Find(What:=Txt, _
LookIn:=xlValues, _
LookAt:=xlPart, _
MatchCase:=False).Row
End Function

HTH. Best wishes Harald

"Tom" skrev i melding
...
Hello again,

how can I check it if hole column contains string which I am lookig for.

for example:
mystring = "test2005"
if mystring in column A give me number of this row

thanks tomas




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Caontains.

set rng = columns(1).Find("test2005")
if not rng is nothing then
msgbox "found at row " & rng.row
End if

Assumes the test2005 would be the hard entered value in the cell and not
part of a larger string or produced by a formula.

--
Regards,
Tom Ogilvy

"Tom" wrote in message
...
Hello again,

how can I check it if hole column contains string which I am lookig for.

for example:
mystring = "test2005"
if mystring in column A give me number of this row

thanks tomas




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 273
Default Caontains.

A mechanical solution that checks an input range is as follows.

Function Row_Match(Ip_Range As range, MatchCell As range) As Integer
Dim i As Integer, j As Integer

For j = 1 To Ip_Range.Columns.count
For i = 1 To Ip_Range.Rows.count
If Ip_Range.Cells(i, j) = MatchCell.Value Then
Row_Match = i
Exit For
End If
Next i
Next j

End Function

Ip_Range is the range to be checked. MatchCell is the cell that contains
what you want to find in the range.


"Tom" wrote:

Hello again,

how can I check it if hole column contains string which I am lookig for.

for example:
mystring = "test2005"
if mystring in column A give me number of this row

thanks tomas



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



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