C
Chet
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
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