Home |
Search |
Today's Posts |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I did what you said with H58000 in a new worksheet in a new workbook.
After clearing the cell, I when to the immediate window and did Activesheet.usedRange and hit enter I then when to A1 in the sheet and the scrollbar was immediately normal. I did Edit=Goto=Special and chose lastcell. The selection remained in A1. xl2003 So worked fine for me. -- Regards, Tom Ogilvy "davidm" wrote in message ... Thanks for all the replies. Having gone through the various variants of applying the Usedrange property to reset the last cell, am I right to conclude that the method is not 100% fail-safe? The following code (from http://www.contextures.com/xlfaqApp.html#Unused) raises that question. Take a fresh Worksheet, and enter a figure in Range($H$58000). Clear the cell and run the code. Result? The scroll bar stays down at $H$58000! To programatically reset the used range, Note: This code may not work correctly if the worksheet contains merged cells. To check your worksheet, you can run the TestForMergedCells code. Sub DeleteUnused() Dim myLastRow As Long Dim myLastCol As Long Dim wks As Worksheet Dim dummyRng As Range For Each wks In ActiveWorkbook.Worksheets With wks myLastRow = 0 myLastCol = 0 Set dummyRng = .UsedRange On Error Resume Next myLastRow = _ .Cells.Find("*", after:=.Cells(1), _ LookIn:=xlFormulas, lookat:=xlWhole, _ searchdirection:=xlPrevious, _ searchorder:=xlByRows).Row myLastCol = _ .Cells.Find("*", after:=.Cells(1), _ LookIn:=xlFormulas, lookat:=xlWhole, _ searchdirection:=xlPrevious, _ searchorder:=xlByColumns).Column On Error GoTo 0 If myLastRow * myLastCol = 0 Then .Columns.Delete Else .Range(.Cells(myLastRow + 1, 1), _ .Cells(.Rows.Count, 1)).EntireRow.Delete .Range(.Cells(1, myLastCol + 1), _ .Cells(1, .Columns.Count)).EntireColumn.Delete End If End With Next wks End Sub -- davidm ------------------------------------------------------------------------ davidm's Profile: http://www.excelforum.com/member.php...o&userid=20645 View this thread: http://www.excelforum.com/showthread...hreadid=473521 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Resetting cells to zero value. | New Users to Excel | |||
Resetting cell format from TEXT to NUMERIC and DATE | Excel Discussion (Misc queries) | |||
resetting last cell | Excel Discussion (Misc queries) | |||
Resetting the end of a worksheet | New Users to Excel | |||
Used Range is not resetting | Excel Programming |