Why are you declaring fromdate as a string???
> Hi,
>
[quoted text clipped - 19 lines]
> Selection.Offset(1, 0).Select
> Loop
Heera - 12 May 2008 10:34 GMT
Then how should i declare?
I am new to the world of Macro and I am not even a programmer.
My problem.
I have two workbooks named "ramp plan macro" and "Hiring Plan"
This report depends upon the dates.
The macro should start working from the date which i have declared in
the "ramp pan macro" workbook.
Joel - 12 May 2008 10:46 GMT
there are two problems
1) Do Until Selection.Value = "fromdate"
fromdate is a variable, remove the double quotes. Your code is looking for
the word "fromdate".
2) Dates in excel are not strings. Change the declaration to Variant.
Dim fromdate As Variant
> Then how should i declare?
> I am new to the world of Macro and I am not even a programmer.
[quoted text clipped - 7 lines]
> The macro should start working from the date which i have declared in
> the "ramp pan macro" workbook.
Hi
I don't know, what format you have for Macro!C12 and for 'C LLC'!A:A, but
fromdate variable is a string, not a date. And whenever you compare a string
and date in VBA, they don't match.
Another remark - don't hop around the sheets of workbook - when more sheets
are involved, it makes user dizzy. And more importantly - moving cursor
around takes too much time.
So my advice is a code like:
Sub RamPlan()
Dim fromdate As Date, tabledate As Date
Dim lastrow As Long, i As Long
Dim found As Boolean
' the cell you are reading date from MUST be formatted as date, and the
value MUST be entered in valid date format
fromdate=Sheets("Macro").Range("C12")
tabledate=0
i=0
found=False
lastrow=Sheets("C LLC").UsedRange.Row()
For i=1 To lastrow-1
tabledate=Sheets("C LLC").Range("A" & 2+i)
If tabledate=fromdate
found=True
' what to do when date was found
Exit For
Else
' what to do when date wasn't found yet
End if
If found=False Then
' what to do when there wasn't such date in table at all
End If
Next i
End Sub

Signature
Arvi Laanemets
( My real mail address: arvi.laanemets<at>tarkon.ee )
> Hi,
>
[quoted text clipped - 19 lines]
> Selection.Offset(1, 0).Select
> Loop