Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 98
Default Code is not detecting the date.

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Code is not detecting the date.

Why are you declaring fromdate as a string???

"Heera" wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 98
Default Code is not detecting the date.

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.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 510
Default Code is not detecting the date.

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


--
Arvi Laanemets
( My real mail address: arvi.laanemets<attarkon.ee )


"Heera" wrote in message
...
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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Code is not detecting the date.

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


"Heera" wrote:

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.


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
Detecting Duplicate Sums - Worksheet code [email protected] Excel Discussion (Misc queries) 0 September 27th 07 02:20 AM
Detecting date format Francis Ang[_3_] Excel Programming 1 July 27th 06 03:53 AM
Detecting Macro Code behind a sheet (2) Chris Gorham[_3_] Excel Programming 10 December 31st 03 06:12 PM
Detecting Macro code behind a sheet Chris Gorham[_3_] Excel Programming 3 December 31st 03 01:39 AM
Detecting VBA code Chris Gorham[_3_] Excel Programming 1 November 1st 03 08:34 PM


All times are GMT +1. The time now is 06:41 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"