Results 1 to 10 of 10

Thread: Summary Of Maximum Rows Used Across Each Sheet In A Workbook

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    I filled entire column B with some value with all the other columns empty. It throwed a type mismatch error, and also modified Range("A2") of active sheet with A:B-1. When columns are entirely filled (which is a rare case anyway), we need to conditionally ensure that we get the last row number instead of the first. Similarly goes when the filled cells are discontiguous (like there a set of empty cells in between a single column that is filled till the very last row.
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  2. #2
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    15
    Quote Originally Posted by Excel Fox View Post
    I filled entire column B with some value with all the other columns empty.
    Hmm, I never thought about that possibility (don't know why, I just didn't). Unfortunately, it is back to the drawing boards for me since a completely filled columns screws up two parts of the method I used.

  3. #3
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    15
    Quote Originally Posted by Rick Rothstein View Post
    Unfortunately, it is back to the drawing boards for me...
    Okay, I am back from the drawing board and I think the following code will work correctly in all scenarios discussed previously...
    Code:
    Sub SheetUsageByWorksheet()
      Dim Col As Long, X As Long, MaxRow As Long, LastRow As Long, PrevRow As Long, LastCol As Long
      Dim Addr As String, TextOut As String, Dashed() As String, Spaced() As String, WS As Worksheet
      On Error GoTo NoData
      For Each WS In Worksheets
        Addr = ""
        MaxRow = 0
        LastCol = WS.Cells.Find("*", , xlFormulas, , xlByColumns, xlPrevious).Column
        If LastCol Then
          For Col = 1 To LastCol
            LastRow = WS.Cells(Rows.Count, Col).End(xlUp).Offset(1).Row - 1
            If LastRow > MaxRow Then MaxRow = LastRow
            If Len(Cells(Rows.Count, Col).Formula) > 0 Then LastRow = Rows.Count
            Addr = Trim(Addr & " " & Split(Cells(1, Col).Address, "$")(1) & "-" & LastRow)
          Next
          Dashed = Split(Addr, "-")
          For X = 1 To UBound(Dashed) - 1
            If Val(Dashed(X)) = Val(Dashed(X + 1)) Then Dashed(X) = ":" & Mid(Dashed(X), InStr(Dashed(X), " ") + 1)
          Next
          Addr = Replace(Join(Dashed, "-"), "-:", ":")
          Spaced = Split(Addr)
          For X = 0 To UBound(Spaced)
            If Spaced(X) Like "*:*" Then Spaced(X) = Left(Spaced(X), InStr(Spaced(X), ":")) & Mid(Spaced(X), InStrRev(Spaced(X), ":") + 1)
          Next
          Addr = "For '" & WS.Name & "' tab with up to " & MaxRow & " rows in " & LastCol & " columns." & vbLf & vbLf & Replace(Join(Spaced), " ", "   ") & vbLf & vbLf
        End If
        TextOut = TextOut & Addr
    Continue:
      Next
      MsgBox TextOut
      Exit Sub
    NoData:
      Resume Continue
    End Sub
    Last edited by Rick Rothstein; 09-04-2015 at 07:28 PM.

Similar Threads

  1. Replies: 1
    Last Post: 05-24-2015, 03:02 PM
  2. VBA to Get Sales SUMMARY of Multipple Sheet
    By mag in forum Excel Help
    Replies: 0
    Last Post: 12-27-2012, 07:39 PM
  3. VBA to Get SUMMARY of Multipple Sheet
    By mag in forum Excel Help
    Replies: 10
    Last Post: 12-27-2012, 04:09 PM
  4. Chart Summary help
    By sanjeevi888 in forum Excel Help
    Replies: 1
    Last Post: 07-08-2012, 06:06 PM
  5. Replies: 9
    Last Post: 09-09-2011, 02:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •