LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default Error: Obj variable or With block variable not set

Keep getting an error msg saying "object variable or With block
variable not set" and I'm not sure how to fix it. My code is from a
book Excel 2002 VBA A Programmers Reference by Stephen Bullen,etc al.
Any idea on eliminating the error message? I put X's at the line where
the error msg happens. The code is supposed to eliminate any rows or
columns that only have formatting and nothing else and reset the
LastCell.

Thanks,
Chet

Dim lLastRow As Long
Dim lRealLastRow As Long
Dim lLastColumn As Long
Dim lRealLastColumn As Long

With Range("A1").SpecialCells(xlCellTypeLastCell)
lLastRow = .Row
lLastColumn = .Column
End With

lRealLastRow = _
Cells.Find("*", Range("A1"), xlFormulas, , xlByRows,
xlPrevious).Row

'XXXXXXXXXXXXXXXXXERROR HAPPENING HEREXXXXXXXXXXXXXXXXXX BELOWXXXXXX
lRealLastColumn = _
Cells.Find("*", Range("A1"), xlFormulas, , xlByColumns,
xlPrevious).Column

If lRealLastRow < lLastRow Then
Range(Cells(lRealLastRow + 1, 1), Cells(lLastRow,
1)).EntireRow.Delete
End If
If lRealLastColumn < lLastComn Then
Range(Cells(1, lRealLastColumn + 1), _
Cells(1,
lLastColumn)).entercolumn.Delete
End If

ActiveSheet.UsedRange 'resets LastCell

 
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
Runtime Error '91' Object variable or With block variable not set Alec Coliver Excel Discussion (Misc queries) 2 October 24th 09 02:29 PM
Getting inconsistent Error 91-Object variable or With block variable not set mfq Excel Programming 0 December 14th 05 06:08 PM
Run-time error '91': "Object variable or With block variable not set Mike[_92_] Excel Programming 2 December 30th 04 10:59 AM
Cells.Find error Object variable or With block variable not set Peter[_21_] Excel Programming 2 May 8th 04 02:15 PM
Error 91 - Object variable with block variable not set Jim[_35_] Excel Programming 2 November 27th 03 03:34 AM


All times are GMT +1. The time now is 11:26 AM.

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"