+ Reply to Thread
Results 1 to 4 of 4

Hide rows based on text criteria

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-03-2014
    Location
    Belgrade
    MS-Off Ver
    2010
    Posts
    348

    Exclamation Hide rows based on text criteria

    Hello folks,
    Can someone help me with VBA for this example?
    So, I would like to hide all rows except selected case (sheet "Refresh" - cell A1), in sheets "Summary" and "AAA".

    Thank you in advance.
    Attached Files Attached Files

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Hide rows based on text criteria

    Try:
    Sub foo()
        Dim ws As Worksheet
        Dim rng As Range
        Dim c As Range
        
        For Each ws In ThisWorkbook.Worksheets
            Set c = ws.Columns(2).Find("Section")
            If Not c Is Nothing Then
                Set rng = Range(c.Offset(1, 0), ws.Cells(Rows.Count, 2).End(xlUp))
                Set c = Nothing
                For Each c In rng
                    With c.MergeArea
                        .EntireRow.Hidden = Not .Cells(1).Value = Worksheets("Refresh").Range("A1").Value
                    End With
                Next c
            End If
        Next ws
    End Sub
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Forum Contributor
    Join Date
    11-03-2014
    Location
    Belgrade
    MS-Off Ver
    2010
    Posts
    348

    Re: Hide rows based on text criteria

    Quote Originally Posted by Olly View Post
    Try:
    Sub foo()
        Dim ws As Worksheet
        Dim rng As Range
        Dim c As Range
        
        For Each ws In ThisWorkbook.Worksheets
            Set c = ws.Columns(2).Find("Section")
            If Not c Is Nothing Then
                Set rng = Range(c.Offset(1, 0), ws.Cells(Rows.Count, 2).End(xlUp))
                Set c = Nothing
                For Each c In rng
                    With c.MergeArea
                        .EntireRow.Hidden = Not .Cells(1).Value = Worksheets("Refresh").Range("A1").Value
                    End With
                Next c
            End If
        Next ws
    End Sub
    It works perfectly!
    Thank you very much!

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Hide rows based on text criteria

    Just a comment.

    You are making life complicated by merging cells. Most of us avoid them like the plague - they are just too much trouble and cause too many problems. Apart from which any analysis is seriously compromised.

    I'd urge you to change your layout and capture data in a normalised 2 dimensional data table. In your case have columns for

    Date
    Customer
    Section
    Data
    Value
    'Sheet Name' i.e. AAA, 000 or whatever this analysis is meant to record

    and make each piece of data a record.

    In addition to simplifying any analysis you'll open up the whole wonderful world of the Pivot Table functionality
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

+ 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. VBA to hide rows based on different cells with different criteria
    By Natstin in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-30-2016, 07:07 AM
  2. [SOLVED] Auto-hide/show Rows based on Yes/No Criteria
    By jakeruby in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-20-2015, 04:04 PM
  3. [SOLVED] hide rows, based criteria table
    By elsg in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-03-2014, 05:35 PM
  4. Excel Macro/ VBA that can hide rows based on multiple criteria
    By hody in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-10-2012, 09:04 AM
  5. Automatically hide rows based on criteria before printing
    By scaffdog845 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-07-2011, 01:44 PM
  6. Hide/Unhide Rows based on Criteria
    By Phillycheese5 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-04-2010, 02:11 PM
  7. Hide Rows in Range based on criteria
    By Hot Soup in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-07-2009, 10:16 AM

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