[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.excel.programming

How can I get the row number Based on cell value

Kc-Mass

12/15/2006 11:13:00 AM

I am good with access new with Excel

What I want to do, in VBA, is search Column B and get the row number
for the first occurence of a value. Let's say I am searching for a value of
"Fish" and "Fish" is in B1207. I would just like the Function to give back
the row number 1207.

Something Like:

Function FindRow ( Column, TextToFind)

Code
Code
Findrow = X
End Function

A. Is it possible.

B. Could you give me an idea of what I am looking for and where I
should look.

Thx

Kevin C


11 Answers

an01digital

12/15/2006 11:32:00 AM

0

Hi Kevin,

Try This...

Please note that the function takes the column Number...

Function FindRow(Column1 As Integer, TextToFind As String)
Dim i as integer
Dim cell As Object
For i = 1 To 65536
RowOfText = 0
If Cells(i, Column1).Value <> "" Then
If Cells(i, Column1).Value = TextToFind Then
RowOfText = i
GoTo 8
End If
End If
Next i

8: If RowOfText = 0 Then
FindRow = 0
Else
FindRow = RowOfText
End If

End Function

Regards
Ankur / Kanchan
www.xlmacros.com

Kc-Mass wrote:

> I am good with access new with Excel
>
> What I want to do, in VBA, is search Column B and get the row number
> for the first occurence of a value. Let's say I am searching for a value of
> "Fish" and "Fish" is in B1207. I would just like the Function to give back
> the row number 1207.
>
> Something Like:
>
> Function FindRow ( Column, TextToFind)
>
> Code
> Code
> Findrow = X
> End Function
>
> A. Is it possible.
>
> B. Could you give me an idea of what I am looking for and where I
> should look.
>
> Thx
>
> Kevin C

an01digital

12/15/2006 11:32:00 AM

0

Hi Kevin,

Try This...

Please note that the function takes the column Number...

Function FindRow(Column1 As Integer, TextToFind As String)
Dim i as integer
Dim cell As Object
For i = 1 To 65536
RowOfText = 0
If Cells(i, Column1).Value <> "" Then
If Cells(i, Column1).Value = TextToFind Then
RowOfText = i
GoTo 8
End If
End If
Next i

8: If RowOfText = 0 Then
FindRow = 0
Else
FindRow = RowOfText
End If

End Function

Regards
Ankur / Kanchan
www.xlmacros.com

Kc-Mass wrote:

> I am good with access new with Excel
>
> What I want to do, in VBA, is search Column B and get the row number
> for the first occurence of a value. Let's say I am searching for a value of
> "Fish" and "Fish" is in B1207. I would just like the Function to give back
> the row number 1207.
>
> Something Like:
>
> Function FindRow ( Column, TextToFind)
>
> Code
> Code
> Findrow = X
> End Function
>
> A. Is it possible.
>
> B. Could you give me an idea of what I am looking for and where I
> should look.
>
> Thx
>
> Kevin C

an01digital

12/15/2006 11:32:00 AM

0

Hi Kevin,

Try This...

Please note that the function takes the column Number...

Function FindRow(Column1 As Integer, TextToFind As String)
Dim i as integer
Dim cell As Object
For i = 1 To 65536
RowOfText = 0
If Cells(i, Column1).Value <> "" Then
If Cells(i, Column1).Value = TextToFind Then
RowOfText = i
GoTo 8
End If
End If
Next i

8: If RowOfText = 0 Then
FindRow = 0
Else
FindRow = RowOfText
End If

End Function

Regards
Ankur / Kanchan
www.xlmacros.com

Kc-Mass wrote:

> I am good with access new with Excel
>
> What I want to do, in VBA, is search Column B and get the row number
> for the first occurence of a value. Let's say I am searching for a value of
> "Fish" and "Fish" is in B1207. I would just like the Function to give back
> the row number 1207.
>
> Something Like:
>
> Function FindRow ( Column, TextToFind)
>
> Code
> Code
> Findrow = X
> End Function
>
> A. Is it possible.
>
> B. Could you give me an idea of what I am looking for and where I
> should look.
>
> Thx
>
> Kevin C

an01digital

12/15/2006 11:32:00 AM

0

Hi Kevin,

Try This...

Please note that the function takes the column Number...

Function FindRow(Column1 As Integer, TextToFind As String)
Dim i as integer
Dim cell As Object
For i = 1 To 65536
RowOfText = 0
If Cells(i, Column1).Value <> "" Then
If Cells(i, Column1).Value = TextToFind Then
RowOfText = i
GoTo 8
End If
End If
Next i

8: If RowOfText = 0 Then
FindRow = 0
Else
FindRow = RowOfText
End If

End Function

Regards
Ankur / Kanchan
www.xlmacros.com

Kc-Mass wrote:

> I am good with access new with Excel
>
> What I want to do, in VBA, is search Column B and get the row number
> for the first occurence of a value. Let's say I am searching for a value of
> "Fish" and "Fish" is in B1207. I would just like the Function to give back
> the row number 1207.
>
> Something Like:
>
> Function FindRow ( Column, TextToFind)
>
> Code
> Code
> Findrow = X
> End Function
>
> A. Is it possible.
>
> B. Could you give me an idea of what I am looking for and where I
> should look.
>
> Thx
>
> Kevin C

an01digital

12/15/2006 11:33:00 AM

0

Hi Kevin,

Try This...

Please note that the function takes the column Number...

Function FindRow(Column1 As Integer, TextToFind As String)
Dim i as integer
Dim cell As Object
For i = 1 To 65536
RowOfText = 0
If Cells(i, Column1).Value <> "" Then
If Cells(i, Column1).Value = TextToFind Then
RowOfText = i
GoTo 8
End If
End If
Next i

8: If RowOfText = 0 Then
FindRow = 0
Else
FindRow = RowOfText
End If

End Function

Regards
Ankur / Kanchan
www.xlmacros.com

Kc-Mass wrote:

> I am good with access new with Excel
>
> What I want to do, in VBA, is search Column B and get the row number
> for the first occurence of a value. Let's say I am searching for a value of
> "Fish" and "Fish" is in B1207. I would just like the Function to give back
> the row number 1207.
>
> Something Like:
>
> Function FindRow ( Column, TextToFind)
>
> Code
> Code
> Findrow = X
> End Function
>
> A. Is it possible.
>
> B. Could you give me an idea of what I am looking for and where I
> should look.
>
> Thx
>
> Kevin C

an01digital

12/15/2006 11:33:00 AM

0

Hi Kevin,

Try This...

Please note that the function takes the column Number...

Function FindRow(Column1 As Integer, TextToFind As String)
Dim i as integer
Dim cell As Object
For i = 1 To 65536
RowOfText = 0
If Cells(i, Column1).Value <> "" Then
If Cells(i, Column1).Value = TextToFind Then
RowOfText = i
GoTo 8
End If
End If
Next i

8: If RowOfText = 0 Then
FindRow = 0
Else
FindRow = RowOfText
End If

End Function

Regards
Ankur / Kanchan
www.xlmacros.com

Kc-Mass wrote:

> I am good with access new with Excel
>
> What I want to do, in VBA, is search Column B and get the row number
> for the first occurence of a value. Let's say I am searching for a value of
> "Fish" and "Fish" is in B1207. I would just like the Function to give back
> the row number 1207.
>
> Something Like:
>
> Function FindRow ( Column, TextToFind)
>
> Code
> Code
> Findrow = X
> End Function
>
> A. Is it possible.
>
> B. Could you give me an idea of what I am looking for and where I
> should look.
>
> Thx
>
> Kevin C

an01digital

12/15/2006 11:33:00 AM

0

Hi Kevin,

Try This...

Please note that the function takes the column Number...

Function FindRow(Column1 As Integer, TextToFind As String)
Dim i as integer
Dim cell As Object
For i = 1 To 65536
RowOfText = 0
If Cells(i, Column1).Value <> "" Then
If Cells(i, Column1).Value = TextToFind Then
RowOfText = i
GoTo 8
End If
End If
Next i

8: If RowOfText = 0 Then
FindRow = 0
Else
FindRow = RowOfText
End If

End Function

Regards
Ankur / Kanchan
www.xlmacros.com

Kc-Mass wrote:

> I am good with access new with Excel
>
> What I want to do, in VBA, is search Column B and get the row number
> for the first occurence of a value. Let's say I am searching for a value of
> "Fish" and "Fish" is in B1207. I would just like the Function to give back
> the row number 1207.
>
> Something Like:
>
> Function FindRow ( Column, TextToFind)
>
> Code
> Code
> Findrow = X
> End Function
>
> A. Is it possible.
>
> B. Could you give me an idea of what I am looking for and where I
> should look.
>
> Thx
>
> Kevin C

an01digital

12/15/2006 11:33:00 AM

0

Hi Kevin,

Try This...

Please note that the function takes the column Number...

Function FindRow(Column1 As Integer, TextToFind As String)
Dim i as integer
Dim cell As Object
For i = 1 To 65536
RowOfText = 0
If Cells(i, Column1).Value <> "" Then
If Cells(i, Column1).Value = TextToFind Then
RowOfText = i
GoTo 8
End If
End If
Next i

8: If RowOfText = 0 Then
FindRow = 0
Else
FindRow = RowOfText
End If

End Function

Regards
Ankur / Kanchan
www.xlmacros.com

Kc-Mass wrote:

> I am good with access new with Excel
>
> What I want to do, in VBA, is search Column B and get the row number
> for the first occurence of a value. Let's say I am searching for a value of
> "Fish" and "Fish" is in B1207. I would just like the Function to give back
> the row number 1207.
>
> Something Like:
>
> Function FindRow ( Column, TextToFind)
>
> Code
> Code
> Findrow = X
> End Function
>
> A. Is it possible.
>
> B. Could you give me an idea of what I am looking for and where I
> should look.
>
> Thx
>
> Kevin C

Martin Fishlock

12/15/2006 12:45:00 PM

0

Kevin

Here is another option:

Option Explicit

Function FindRowRevised(Column1 As Integer, TextToFind As String)

Dim c As Range

With ActiveSheet.Columns(Column1)
Set c = .Find(What:=TextToFind, LookIn:=xlValues, LookAt:=xlWhole)
If c Is Nothing Then
FindRowRevised = 0
Else
FindRowRevised = c.Row
End If
End With

End Function

If you decide to use Ankur's suggestion then the i should be a long. Also
with 2007 explicitly declaring 65536 is not good and it may be more advisable
to use cells.rows.count

Function FindRow(Column1 As Integer, TextToFind As String)
Dim i as integer
Dim cell As Object
For i = 1 To 65536
RowOfText = 0
If Cells(i, Column1).Value <> "" Then
If Cells(i, Column1).Value = TextToFind Then
RowOfText = i
GoTo 8
End If
End If
Next i

8: If RowOfText = 0 Then
FindRow = 0
Else
FindRow = RowOfText
End If

End Function

Regards
/ Kanchan

--
Hope this helps
Martin Fishlock
Please do not forget to rate this reply.


"Kc-Mass" wrote:

> I am good with access new with Excel
>
> What I want to do, in VBA, is search Column B and get the row number
> for the first occurence of a value. Let's say I am searching for a value of
> "Fish" and "Fish" is in B1207. I would just like the Function to give back
> the row number 1207.
>
> Something Like:
>
> Function FindRow ( Column, TextToFind)
>
> Code
> Code
> Findrow = X
> End Function
>
> A. Is it possible.
>
> B. Could you give me an idea of what I am looking for and where I
> should look.
>
> Thx
>
> Kevin C
>
>
>

Kc-Mass

12/16/2006 4:26:00 AM

0

Thanks for all the help!

I have it now.

You folks are great!

Kevin C
"Kc-Mass" <connearney_AT_comcast_PERIOD_net> wrote in message
news:_YmdnaLikL2DHh_YnZ2dnUVZ_hy3nZ2d@comcast.com...
>I am good with access new with Excel
>
> What I want to do, in VBA, is search Column B and get the row number
> for the first occurence of a value. Let's say I am searching for a value
> of
> "Fish" and "Fish" is in B1207. I would just like the Function to give
> back
> the row number 1207.
>
> Something Like:
>
> Function FindRow ( Column, TextToFind)
>
> Code
> Code
> Findrow = X
> End Function
>
> A. Is it possible.
>
> B. Could you give me an idea of what I am looking for and where I
> should look.
>
> Thx
>
> Kevin C
>
>