Code:
Sub SheetUsageByWorksheets()
Dim X As Long, MaxRow As Long, LastCol As Long
Dim WS As Worksheet, AddrStr As String, MBxString As String, Addr() As String
For Each WS In Worksheets
MaxRow = 0
LastCol = 0
AddrStr = ""
Erase Addr
On Error Resume Next
LastCol = WS.Cells.Find("*", , xlFormulas, , xlByColumns, xlPrevious).Column
On Error GoTo 0
If LastCol Then
For X = 1 To LastCol
With WS.Cells(Rows.Count, X).End(xlUp).Offset(1)
.Cells = "#N/A"
If .Row - 1 > MaxRow Then MaxRow = .Row - 1
End With
Next
AddrStr = Intersect(WS.UsedRange, WS.Cells.SpecialCells(xlConstants, xlErrors)).Offset(-1).Address(, 0)
WS.UsedRange.Replace "#N/A", "", xlWhole
Addr = Split(AddrStr, ",")
For X = 0 To UBound(Addr)
If Addr(X) Like "*:*" Then Addr(X) = Left(Addr(X), InStrRev(Addr(X), "$", InStr(Addr(X), ":")) - 1) & Mid(Addr(X), InStr(Addr(X), ":"))
Addr(X) = Replace(Addr(X), "$", "-")
Next
With WS.Cells(MaxRow + 1, "A").Resize(, UBound(Addr) + 1)
.Cells = Addr
.Sort .Cells, xlAscending, , , , , , xlNo, , , xlLeftToRight
AddrStr = "For '" & WS.Name & "' tab with up to " & MaxRow & " rows in " & LastCol & " columns." & vbLf & vbLf & Join(Application.Index(.Value, 1, 0), " ") & vbLf & vbLf
.Clear
End With
End If
MBxString = MBxString & AddrStr
Next
MsgBox MBxString
End Sub
Bookmarks