From: Pas on
I have the following code which deletes all rows older then 365 days:

Sub Del_Oldies()
LR = Cells(Rows.Count, 1).End(xlUp).Row
For R = LR To 1 Step -1
If Date - Cells(R, 1) > 365 Then Cells(R, 1).EntireRow.Delete
Next
End Sub

I keep getting error message
Compile error:
Variable not defined
with "LR =" highlighted in blue

How do I modify this code to declare the variables R, and LR as Integers .

From: ozgrid.com on
Dim LR As Long
Dim R As Long

As the 1st 2 lines in your Procedure.



--
Regards
Dave Hawley
www.ozgrid.com
"Pas" <Pas(a)discussions.microsoft.com> wrote in message
news:3EF4D99C-5FA9-4032-AA32-23D4986E4D06(a)microsoft.com...
>I have the following code which deletes all rows older then 365 days:
>
> Sub Del_Oldies()
> LR = Cells(Rows.Count, 1).End(xlUp).Row
> For R = LR To 1 Step -1
> If Date - Cells(R, 1) > 365 Then Cells(R, 1).EntireRow.Delete
> Next
> End Sub
>
> I keep getting error message
> Compile error:
> Variable not defined
> with "LR =" highlighted in blue
>
> How do I modify this code to declare the variables R, and LR as Integers .
>

From: Mike H on
Hi,

Somewhere else you may have declared

Option Explicit
or

In VB option you may have cheked 'Require variable declaration'

Both of which means all variables have to be declared so declare it at the
start of your code

Sub Del_Oldies()
Dim R as Long, LR as Long
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Pas" wrote:

> I have the following code which deletes all rows older then 365 days:
>
> Sub Del_Oldies()
> LR = Cells(Rows.Count, 1).End(xlUp).Row
> For R = LR To 1 Step -1
> If Date - Cells(R, 1) > 365 Then Cells(R, 1).EntireRow.Delete
> Next
> End Sub
>
> I keep getting error message
> Compile error:
> Variable not defined
> with "LR =" highlighted in blue
>
> How do I modify this code to declare the variables R, and LR as Integers .
>
From: Roger Govier on
Hi

I would use Longs rather than Integers

Sub Del_Oldies()
Dim LR as long, R as long
LR = Cells(Rows.Count, 1).End(xlUp).Row
For R = LR To 1 Step -1
If Date - Cells(R, 1) > 365 Then Cells(R, 1).EntireRow.Delete
Next
End Sub

--
Regards
Roger Govier

Pas wrote:
> I have the following code which deletes all rows older then 365 days:
>
> Sub Del_Oldies()
> LR = Cells(Rows.Count, 1).End(xlUp).Row
> For R = LR To 1 Step -1
> If Date - Cells(R, 1) > 365 Then Cells(R, 1).EntireRow.Delete
> Next
> End Sub
>
> I keep getting error message
> Compile error:
> Variable not defined
> with "LR =" highlighted in blue
>
> How do I modify this code to declare the variables R, and LR as Integers .
>
From: Pas on
Thanks guys,
I get a runtime error 1004
with the following highlighted:
Cells(R, 1).EntireRow.Delete

"Roger Govier" wrote:

> Hi
>
> I would use Longs rather than Integers
>
> Sub Del_Oldies()
> Dim LR as long, R as long
> LR = Cells(Rows.Count, 1).End(xlUp).Row
> For R = LR To 1 Step -1
> If Date - Cells(R, 1) > 365 Then Cells(R, 1).EntireRow.Delete
> Next
> End Sub
>
> --
> Regards
> Roger Govier
>
> Pas wrote:
> > I have the following code which deletes all rows older then 365 days:
> >
> > Sub Del_Oldies()
> > LR = Cells(Rows.Count, 1).End(xlUp).Row
> > For R = LR To 1 Step -1
> > If Date - Cells(R, 1) > 365 Then Cells(R, 1).EntireRow.Delete
> > Next
> > End Sub
> >
> > I keep getting error message
> > Compile error:
> > Variable not defined
> > with "LR =" highlighted in blue
> >
> > How do I modify this code to declare the variables R, and LR as Integers .
> >
> .
>