+ Reply to Thread
Results 1 to 6 of 6

VBA to hide/show rows, if column B is blank

  1. #1
    Registered User
    Join Date
    09-18-2017
    Location
    Richmond, Virginia
    MS-Off Ver
    2013
    Posts
    4

    Lightbulb VBA to hide/show rows, if column B is blank

    I have created a cashflow template that can be used for any size job in terms of line items (Y Axis) and duration (X axis). I have written VBA to hide/show cells, but I would like to create button that when selected will hide/show all rows if that row's B cell is blank I.E. will not be used. This would be optimal as it would clean up my table to only show actively used line items. I have tried to write this code a couple different ways, but have gotten tripped up when it comes to accounting not only for blank cells in row B, but when the cells are populated and I still "lose" them. Any direction/advice would be very appreciated.

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: VBA to hide/show rows, if column B is blank

    Welcome to the forum
    This code toggles between hide and show
    Please Login or Register  to view this content.
    Try in attached file
    Attached Files Attached Files
    Last edited by kev_; 09-19-2017 at 08:30 AM.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  3. #3
    Registered User
    Join Date
    09-18-2017
    Location
    Richmond, Virginia
    MS-Off Ver
    2013
    Posts
    4

    Re: VBA to hide/show rows, if column B is blank

    Thanks for the help, and the warm welcome! The one issue with the code above is that (and this is partially on me for not explaining properly) the rows to be hidden per the blank cells... These cells are pulled from another source so they aren't actually blank, and excel reads them as a 0 "-". Is there a quick adjustment I can make for this to be processed properly?

  4. #4
    Registered User
    Join Date
    09-18-2017
    Location
    Richmond, Virginia
    MS-Off Ver
    2013
    Posts
    4

    Re: VBA to hide/show rows, if column B is blank

    I have found a solution.

    This will run and hide all rows when the cell in column B=0. When more data is added and more lines become populated, it can be run again and the new data will appear
    PHP Code: 
    Sub ShowUsedRowsPerItemCell()
        
    BeginRow 6
        EndRow 
    401
        ChkCol 
    2

        
    For RowCnt BeginRow To EndRow
            
    If Cells(RowCntChkCol).Value 0 Then
                Cells
    (RowCntChkCol).EntireRow.Hidden True
            
    Else
                
    Cells(RowCntChkCol).EntireRow.Hidden False
            End 
    If
        
    Next RowCnt
    End Sub 

  5. #5
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: VBA to hide/show rows, if column B is blank

    Glad you found your solution
    Blank cells are a bit of a problem if they appear to be empty when they are truly not
    Thanks for posting your solution.
    To keep things nice and tidy, click on ThreadTools at top of thread and mark thread as solved
    Last edited by kev_; 09-19-2017 at 09:37 AM.

  6. #6
    Registered User
    Join Date
    09-18-2017
    Location
    Richmond, Virginia
    MS-Off Ver
    2013
    Posts
    4

    Re: VBA to hide/show rows, if column B is blank

    I have battles with "blank" cells everyday Thanks for everything! :D

+ 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. Hide blank rows in column -> in another column
    By InvalidTxtString in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-05-2016, 11:36 AM
  2. How to autofilter to only show rows that have a blank value for the Q column
    By ks100 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-12-2015, 02:07 PM
  3. 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
  4. [SOLVED] Hide Rows if the cell in a certain column is blank or zero
    By Shannon561 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-16-2014, 07:00 AM
  5. [SOLVED] Hide/show rows with 0 value in column D and E based on case selection
    By say0nara in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-31-2013, 06:34 AM
  6. [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
  7. Replies: 0
    Last Post: 12-08-2011, 03:37 PM

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