Run time error

  • Thread starter Thread starter jee22
  • Start date Start date
J

jee22

Can some kind person explain why this code
produces Run time Error 1004

LastRow = .Cells(.Rows.count, "A").End(x1Up).row
 
sorry I should have included all the code as follows

Dim c, n, row, e, col As Integer
Dim LastRow As Long
Dim t, celladdr As String
Dim wks As Worksheet
Set wks = ActiveSheet
With wks
LastRow = .Cells(.Rows.count, "A").End(xlUp).row
End With

It is the LastRow = that is generating the error
Thanks
 
jee22,

Yours code works for me in XL 97 as copied. I think that the reason for the
error may be the fact that you are using a VBA reserved name - Row - as a
variant by DIMming it. Note that unlike Microsoft Basic, declaring multiple
variables separated by commas declares them all as variants except the last
one, which is declared as a type.


HTH

Sandy
 
XLUP = x(ELL)up

You have
x1Up X(one)up.



Can some kind person explain why this code
produces Run time Error 1004

LastRow = .Cells(.Rows.count, "A").End(x1Up).row
 
One way to avoid some of these problems is to add "Option Explicit" to the top
of each module.

This will force you to declare all the variables that you use. If it ain't
declared, it ain't compiling!

It may seem like more work, but it'll save a lot of time (1 vs. 1).

And if you declare your variables using specific types/objects, you'll get VBA's
intellisense to pop up--which saves lots of time.


You can even have Excel add "option explicit" to new modules for you:

Inside the VBE, tools|Options|editor tab|check "require variable declaration"


Thanks to all for the help ......... (none as blind as those who type in
code!)
 
Back
Top