Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
PAS PAS is offline
external usenet poster
 
Posts: 26
Default Declare variables to a code?

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 .

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 464
Default Declare variables to a code?

Dim LR As Long
Dim R As Long

As the 1st 2 lines in your Procedure.



--
Regards
Dave Hawley
www.ozgrid.com
"Pas" wrote in message
...
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 .


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default Declare variables to a code?

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 .

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 376
Default Declare variables to a code?

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 .

  #5   Report Post  
Posted to microsoft.public.excel.misc
PAS PAS is offline
external usenet poster
 
Posts: 26
Default Declare variables to a code?

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 .

.



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Declare variables to a code?

Any chance that your worksheet is protected?

Pas wrote:

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 .

.


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.misc
PAS PAS is offline
external usenet poster
 
Posts: 26
Default Declare variables to a code?

Thanks Dave, didnt think of that!!! I'll try it.

"Dave Peterson" wrote:

Any chance that your worksheet is protected?

Pas wrote:

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 .

.


--

Dave Peterson
.

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
Declare Variables in Array Mike H. Excel Discussion (Misc queries) 2 March 11th 09 12:33 PM
Declare and Set Public variables jlclyde Excel Discussion (Misc queries) 2 January 28th 09 02:16 PM
how to declare local variables for Excel.Workbook at runtime. Daffo Excel Discussion (Misc queries) 0 October 9th 06 12:19 PM
How to efficiently declare variables Jeff Excel Discussion (Misc queries) 2 June 29th 06 01:56 PM
How to declare a dynamic array Peter Rooney Excel Discussion (Misc queries) 4 April 13th 05 01:25 PM


All times are GMT +1. The time now is 05:37 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"