Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Detecting Duplicate Sums - Worksheet code | Excel Discussion (Misc queries) | |||
Detecting date format | Excel Programming | |||
Detecting Macro Code behind a sheet (2) | Excel Programming | |||
Detecting Macro code behind a sheet | Excel Programming | |||
Detecting VBA code | Excel Programming |