LastRow results in Run-time error

  • Thread starter Thread starter steveski
  • Start date Start date
S

steveski

I’m using the following code to (hopefully) step through each populate
row of my Data Entry sheet. I am using Excel 2000. I have a problem an
questions:

- Problem: “LastRow” is giving me a “Run-time error ‘438’: Objec
doesn’t support this property or method”
- Questions: Is the “With Sheets("Data Entry").Range("PTSource")
statement sufficient to ensure the For/Next loop steps through al
populated rows? Is the “LastRow” statement redundant or confllicting?

Thanks.

With Sheets("Data Entry").Range("PTSource")

LastRow = .UsedRange.Rows.Count

For i = 2 To LastRow

Etc
 
Hi Steve

Usedrange you can't use on a range.
You can use it on a sheet like this
ActiveSheet.UsedRange

Try this to loop through the rows in your named range

Sub test()
With Sheets("Data Entry").Range("PTSource")
firstrow = .Cells(1).Row
LastRow = .Rows.Count + firstrow - 1
End With
For I = firstrow To LastRow
MsgBox I
Next
End Sub
 
And just as an addendum, if the reason you are stepping through is to
potentially delete any rows at all, then always start from the bottom and work
up, not the other way round, otherwise you will hit problems.

--
Regards
Ken....................... Microsoft MVP - Excel
Sys Spec - Win XP Pro / XL 00/02/03

----------------------------------------------------------------------------
It's easier to beg forgiveness than ask permission :-)
----------------------------------------------------------------------------



Ron de Bruin said:
Hi Steve

Usedrange you can't use on a range.
You can use it on a sheet like this
ActiveSheet.UsedRange

Try this to loop through the rows in your named range

Sub test()
With Sheets("Data Entry").Range("PTSource")
firstrow = .Cells(1).Row
LastRow = .Rows.Count + firstrow - 1
End With
For I = firstrow To LastRow
MsgBox I
Next
End Sub
 
Example you can find on this page
http://www.rondebruin.nl/delete.htm

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)




Ken Wright said:
And just as an addendum, if the reason you are stepping through is to
potentially delete any rows at all, then always start from the bottom and work
up, not the other way round, otherwise you will hit problems.
 
Back
Top