Last Row/Column Question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a quick way to identify the last row and last column of data in a
worksheet and hide all rows and columns beyond this point?
 
Sub HideUnused()
Rows(LastRow + 1 & ":" & Rows.Count).Hidden = True
Columns(LastCol + 1).Resize(, Columns.Count - LastCol).Hidden = True
End Sub

'-----------------------------------------------------------------
Function LastRow() As Long
'-----------------------------------------------------------------
LastRow = Cells.Find(What:="*", _
After:=Range("A1"), _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
End Function

'-----------------------------------------------------------------
Function LastCol() As Long
'-----------------------------------------------------------------
LastCol = Cells.Find(What:="*", _
After:=Range("A1"), _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
End Functio

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
try this one:

Sub hideRows()
Rows("A1:iv65536").EntireRow.Hidden = False
ActiveSheet.UsedRange.Select
ActiveCell.Offset(2, 0).Range("A1").Select
Rows(Selection.Address & ":IV65536").EntireRow.Hidden = True
Range("A1").Select
End Sub

don not forget to rate me
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top