+ Reply to Thread
Results 1 to 7 of 7

Macro to loop through column, if blank blank cells then hide rows

Hybrid View

  1. #1
    Registered User
    Join Date
    11-28-2018
    Location
    Netherlands
    MS-Off Ver
    Office 13
    Posts
    30

    Macro to loop through column, if blank blank cells then hide rows

    Hi all.

    I am trying to get a macro to automatically hide-rows based on if a condition is met.

    Capture.JPG

    I have severale tables where there are formulas outputing summary statistics for People. The spreadsheet is sample as it had sensitive info, each Person in Col C, will have a value shown in Col F after BUY or SELL, but if the person did nothing it would be blank in either of those fields. I would like a macro to go down the column hiding those people that have empty values for either Buy/Sell, as these People have nothing do with the current statistics we are comparing since they are not involved.

    i.e. John can either have a value in F10 or F11, or none at all, if there is none at all I want F10/F11 rows hidden. Next, macro would look at Patrick in F12/F13 if there is no value in any of those rows then hide, if there is indeed a value in any of those cells go to the next person Mike and check F14/F15 for values, and so on...

    If anyone out there has any idea how to do this I would be so thankful, would appreciate advise and how I should go about this.

    hope to hear from you!

    Stein
    Attached Files Attached Files
    Last edited by stein7; 05-23-2019 at 10:17 PM.

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this ‼


    A demonstration as a beginner starter :

    PHP Code: 
    Sub Demo()
            
    Dim VR&
            
    Application.ScreenUpdating False
        
    For Each V In [{8,21,34}]
            
    With Cells(V3).CurrentRegion
                
    For 3 To .Rows.Count Step 2
                    With 
    .Cells(R4).Resize(2)
                        If 
    Application.CountBlank(.Cells) = 2 Then .EntireRow.Hidden True
                    End With
                Next
            End With
        Next
            Application
    .ScreenUpdating True
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 05-25-2019 at 05:09 AM. Reason: ScreenUpdating optimization …

  3. #3
    Registered User
    Join Date
    11-28-2018
    Location
    Netherlands
    MS-Off Ver
    Office 13
    Posts
    30
    Thank you for your reply really appreciate it, I’m having trouble implementing this on my real sheet, it didn’t work at first go, let me see what I can do.

  4. #4
    Registered User
    Join Date
    11-28-2018
    Location
    Netherlands
    MS-Off Ver
    Office 13
    Posts
    30

    Re: Hi ! Try this ‼

    Hi Marc, I have had trouble with trying to implement this on my real sheet due to the layout being slightly different, I attempted to reflect the changes in the code, but it is not picking it, maybe because I am not the best in coding and forgetting to change a parameter in your code. I have attached a sample workbook that accurately reflects the positioning in my real sheet. Would tremendously appreciate your assistance on doing a couple of modifications for it to be able to run on this new similar sample sheet.
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb Try this !

    It's weird to not attach a real layout workbook in the initial post except if you are able to modify any code …

    According to your last attachment, paste this demonstration to the Sheet1(Summary Stats) worksheet module :

    PHP Code: 
    Sub Demo1()
           
    Dim A$, Rg As Range
           Application
    .ScreenUpdating False
        With Me
    .UsedRange.Columns(5)
               
    Set Rg = .Find("BUY", , , xlWhole)
            If 
    Not Rg Is Nothing Then
               A 
    Rg.Address
                
    Do
                    
    With Rg(12).Resize(2)
                        If 
    Application.CountBlank(.Cells) = 2 Then .EntireRow.Hidden True
                    End With
                       Set Rg 
    = .FindNext(Rg)
                
    Loop Until Rg.Address A
               Set Rg 
    Nothing
            End 
    If
        
    End With
           Application
    .ScreenUpdating True
    End Sub 
    ► Do you like it ? ► ► So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 05-25-2019 at 05:06 AM. Reason: ScreenUpdating optimization …

  6. #6
    Registered User
    Join Date
    11-28-2018
    Location
    Netherlands
    MS-Off Ver
    Office 13
    Posts
    30

    Re: Try this !

    thank you so much, I really appreciate

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Macro to loop through column, if blank blank cells then hide rows


    ► If you really appreciate ► ► so click on bottom left star icon « ★ Add Reputation » of my code post, thanks …

+ 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 to remove rows if all cells from columns are blank except first column
    By tikistat in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-05-2017, 08:08 AM
  2. [SOLVED] Macro for Hide blank rows and Unhide the rows with cells
    By Neilesh Kumar in forum Excel General
    Replies: 4
    Last Post: 04-12-2017, 06:06 AM
  3. Hide rows for blank Cells when there is another blank cell below
    By bilich in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-16-2016, 08:29 PM
  4. Hide Rows for First Set of Consecutive Blank Cells in Column
    By pastuslm in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-22-2015, 03:22 PM
  5. [SOLVED] Macro to fill blank cells in column A based on non-blank cells
    By ktalamantez in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-28-2014, 02:47 PM
  6. Macro to delete blank rows if column I is blank for the row
    By tiger10012 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-10-2013, 03:01 PM
  7. [SOLVED] Hide any rows 5 through 16 in which column H is blank
    By Triscia in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-14-2013, 04:30 PM

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