+ Reply to Thread
Results 1 to 3 of 3

VBA Excel Macro Hide Rows Based on Cell Value

Hybrid View

  1. #1
    Registered User
    Join Date
    07-08-2017
    Location
    Minnesota
    MS-Off Ver
    Microsoft Office 2016
    Posts
    78

    VBA Excel Macro Hide Rows Based on Cell Value

    Hello,

    I am looking for VBA to hide rows based on if a cell value is zero and then loop down the spreadsheet and hide all rows with the corresponding cell value as zero. I know how to do this when it is a bit more simple and less variables.

    The number of lines for each account can vary on this spreadsheet. The attached sheet is a smaller spreadsheet but in reality there is about 150 accounts, so something that can easily scan through each section not showing a balance on the Trial Balance column and hiding that section of rows would be really nice through a macro and not having to manually do it. Any help is appreciated!!

    Thanks!
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,789

    Re: VBA Excel Macro Hide Rows Based on Cell Value

    How about
    Sub hideRows()
       Dim Ar As Areas
       Dim i As Long
       
       With Range("A8", Range("A" & Rows.Count).End(xlUp))
          .Replace "*Total*", "=xxxTotal", xlPart, , False, , False, False
          Set Ar = .SpecialCells(xlFormulas, xlErrors).Areas
          .Replace "=xxxTotal", "Total", xlPart, , False, , False, False
       End With
       For i = 1 To Ar.Count
          If Ar(i).Offset(, 6) = 0 Then
             If i = 1 Then
                Rows("9:" & Ar(i).Row).Hidden = True
             Else
                Rows(Ar(i - 1).Row & ":" & Ar(i).Row).Hidden = True
             End If
          End If
       Next i
    End Sub

  3. #3
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,050

    Re: VBA Excel Macro Hide Rows Based on Cell Value

    Try:
    Sub HideRows()
        Application.ScreenUpdating = False
        Dim LastRow As Long
        LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        Dim rng As Range
        Dim total As Range
        Dim totalRow As Long
        For Each rng In Range("A10:A" & LastRow)
            If IsNumeric(Left(rng, 6)) Then
                Set total = Range("A" & rng.Row & ":A" & LastRow).Find("Total")
                totalRow = total.Row
                If Cells(totalRow, 7) = 0 Then
                    Rows(rng.Row - 1 & ":" & totalRow).EntireRow.Hidden = True
                Else
                    Rows(rng.Row - 1 & ":" & totalRow).EntireRow.Hidden = False
                End If
            End If
        Next rng
        Application.ScreenUpdating = True
    End Sub
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Macro for Hide Or Unhide Rows based on Cell Text
    By Neilesh Kumar in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 04-26-2017, 12:03 PM
  2. [SOLVED] Macro to hide rows based on cell text
    By pauldaddyadams in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 07-13-2016, 08:52 AM
  3. Macro to Hide/Unhide Rows Based on Cell Value
    By mlancaster24 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-07-2015, 01:20 PM
  4. Macro to Hide rows based on a cell value
    By pdalal in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-17-2015, 05:25 PM
  5. Macro that will delete/hide rows based on a cell value
    By dwilkinson12 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 11-27-2014, 05:59 AM
  6. [SOLVED] Macro to automatically hide or unhide rows based on either a value or no value in a cell
    By WFP111 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-04-2013, 12:28 PM
  7. Macro to hide rows based on cell
    By aeewing in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-13-2011, 10:24 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1