A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data
Hi,
a/before
.
b/after
.
vba
Sub Hide_Empty_RowsColumns()
'## 30/04/2024 ##
Dim ws As Worksheet
Set ws = ActiveSheet
Dim LastRow As Integer, LastCol As Integer, x As Integer
Application.ScreenUpdating = False
ws.Columns(1).EntireRow.Hidden = False
ws.Rows(1).EntireColumn.Hidden = False
LastRow = ws.Cells.Find(What:="*", _
SearchOrder:=xlByRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row
LastCol = ws.Cells.Find(What:="*", _
SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, LookIn:=xlValues).Column
'
For i = LastRow To 1 Step -1
x = WorksheetFunction.CountBlank(ws.Cells(i, 1).Resize(, LastCol))
If x = LastCol Then
ws.Rows(i).Hidden = True
End If
Next i
For i = LastCol To 1 Step -1
x = WorksheetFunction.CountBlank(ws.Cells(1, i).Resize(LastRow))
If x = LastRow Then
ws.Columns(i).Hidden = True
End If
Next i
Application.ScreenUpdating = True
End Sub