ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Return the Row of a Variable's location (https://www.excelbanter.com/excel-discussion-misc-queries/123612-return-row-variables-location.html)

xjetjockey

Return the Row of a Variable's location
 
I'm a total beginner with VBA, so my apologies up front.
I have a table with Column A filled with dates.
I am trying to locate the row number of the cell that contains the
matching date to my variable named LASTDATE. How do I do this?
Thanks.
Robert


Gary''s Student

Return the Row of a Variable's location
 
Sub marine()
LASTDATE = DateValue("12/30/2006")
For i = 1 To 100
If Cells(i, "A").Value = LASTDATE Then
MsgBox (Cells(i, "A").Row)
Exit Sub
End If
Next
End Sub


and in the worksheet column A has:
=TODAY()
=A1+1
=A2+1
=A3+1
=A4+1
=A5+1
=A6+1
=A7+1
=A8+1
=A9+1
=A10+1
=A11+1
=A12+1
=A13+1
=A14+1
=A15+1
=A16+1
=A17+1
=A18+1
=A19+1
=A20+1
=A21+1
=A22+1
=A23+1
and displays:
12/22/2006
12/23/2006
12/24/2006
12/25/2006
12/26/2006
12/27/2006
12/28/2006
12/29/2006
12/30/2006
12/31/2006
1/1/2007
1/2/2007
1/3/2007
1/4/2007
1/5/2007
1/6/2007
1/7/2007
1/8/2007
1/9/2007
1/10/2007
1/11/2007
1/12/2007
1/13/2007
1/14/2007

Note the use of the function DateValue()
--
Gary's Student


"xjetjockey" wrote:

I'm a total beginner with VBA, so my apologies up front.
I have a table with Column A filled with dates.
I am trying to locate the row number of the cell that contains the
matching date to my variable named LASTDATE. How do I do this?
Thanks.
Robert




All times are GMT +1. The time now is 03:34 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com