Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / May 2008

Tip: Looking for answers? Try searching our database.

Code is not detecting the date.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Heera - 12 May 2008 09:26 GMT
Hi,

Here is my code.

The value in "C12" range is a date but my loop is not able to detect
the date in the column.

Sub RamPlan()

   Workbooks("Ramp Plan Macro.xls").Activate
   Sheets("Macro").Select

   Dim fromdate As String

   fromdate = Range("c12").Value

   Windows(hirename).Activate
   Sheets("C LLC").Select
   Range("A2").Select

   Do Until Selection.Value = "fromdate"
   Selection.Offset(1, 0).Select
   Loop
Joel - 12 May 2008 10:09 GMT
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.
Arvi Laanemets - 12 May 2008 10:40 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.