Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 138
Default Get the row number that matches my value

I would like to return the row number in which there is a match to a my
variable.

In this case a is the value I am looking for and its in column a of
Sheets("Sec1").Range("A1:A500")

How should I go about this? Am i going in the right direction by using
Cells.Find?

Bruce

Sub myDateRow()

a = Format(Sheets("Shares").Range("D9"), "yyyymmdd")

With Sheets("Sec1").Range("A1:A500")
Range("A1").Select
Cells.Find(What:=""" & a & """, After:=ActiveCell,
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, MatchCase:=False).Activate
End With
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 252
Default Get the row number that matches my value

try

Sub myDateRow()
Dim a As Date
a = Sheets("Shares").Range("D9")

With Sheets("Sec1").Range("A1:A500")
.Range("A500").Select
.Cells.Find(What:=a, After:=ActiveCell, _
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False).Activate
End With
End Sub



"Bruce" wrote:

I would like to return the row number in which there is a match to a my
variable.

In this case a is the value I am looking for and its in column a of
Sheets("Sec1").Range("A1:A500")

How should I go about this? Am i going in the right direction by using
Cells.Find?

Bruce

Sub myDateRow()

a = Format(Sheets("Shares").Range("D9"), "yyyymmdd")

With Sheets("Sec1").Range("A1:A500")
Range("A1").Select
Cells.Find(What:=""" & a & """, After:=ActiveCell,
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, MatchCase:=False).Activate
End With
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default Get the row number that matches my value

Try this:


Function GetRow(sText) As Long

Dim lRow As Long
lRow = 0

On Error Resume Next
lRow = Sheets("Sheet1").Range("A1:A500").Find(What:=sText , _
LookIn:=xlValues, LookAt:=xlPart,
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False).Row
On Error GoTo 0

GetRow = lRow

End Function


Tim

"Bruce" wrote in message
...
I would like to return the row number in which there is a match to a
my
variable.

In this case a is the value I am looking for and its in column a of
Sheets("Sec1").Range("A1:A500")

How should I go about this? Am i going in the right direction by
using
Cells.Find?

Bruce

Sub myDateRow()

a = Format(Sheets("Shares").Range("D9"), "yyyymmdd")

With Sheets("Sec1").Range("A1:A500")
Range("A1").Select
Cells.Find(What:=""" & a & """, After:=ActiveCell,
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, MatchCase:=False).Activate
End With
End Sub



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
Add number before text that matches criteria Carole Excel Worksheet Functions 3 May 8th 08 09:38 PM
Counting number of times data matches Colin Excel Worksheet Functions 5 September 12th 07 08:28 AM
Change fmt of a cell if number matches any in a range of cells? SteveR Excel Worksheet Functions 2 April 20th 06 05:32 PM
Excel filter no longer calculates the number of matches SReed Excel Discussion (Misc queries) 1 March 29th 05 01:39 PM
How do I count number of cels the matches 2 conditions ? Abra Excel Worksheet Functions 2 February 27th 05 08:56 PM


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