Results 1 to 13 of 13

VBA - Condense code for hiding/unhiding cell based on value in cell above

Threaded View

  1. #1
    Registered User
    Join Date
    07-28-2013
    Location
    Chicago, Illinois
    MS-Off Ver
    Excel 2010
    Posts
    8

    VBA - Condense code for hiding/unhiding cell based on value in cell above

    Hi all,

    I have been working on this code, and I want it to check the cell above for a certain range of cells. If the cell above is empty then hide the entire row. If the cell above is not empty then show the entire row. Since this is being applied to several ranges within the same worksheet, I was wondering how to condense the coding. Any help would be great!

    This sample is to individually hide rows B29:B47 based on values in the cell above:

    Private Sub Worksheet_Change(ByVal Target As Range)
        
       ' Budget area
        If Range("B28").Value = 0 Then Range("B29").EntireRow.Hidden = True
        If Range("B29").Value = 0 Then Range("B30").EntireRow.Hidden = True
        If Range("B30").Value = 0 Then Range("B31").EntireRow.Hidden = True
        If Range("B31").Value = 0 Then Range("B32").EntireRow.Hidden = True
        If Range("B32").Value = 0 Then Range("B33").EntireRow.Hidden = True
        If Range("B33").Value = 0 Then Range("B34").EntireRow.Hidden = True
        If Range("B34").Value = 0 Then Range("B35").EntireRow.Hidden = True
        If Range("B35").Value = 0 Then Range("B36").EntireRow.Hidden = True
        If Range("B36").Value = 0 Then Range("B37").EntireRow.Hidden = True
        If Range("B37").Value = 0 Then Range("B38").EntireRow.Hidden = True
        If Range("B38").Value = 0 Then Range("B39").EntireRow.Hidden = True
        If Range("B39").Value = 0 Then Range("B40").EntireRow.Hidden = True
        If Range("B40").Value = 0 Then Range("B41").EntireRow.Hidden = True
        If Range("B41").Value = 0 Then Range("B42").EntireRow.Hidden = True
        If Range("B42").Value = 0 Then Range("B43").EntireRow.Hidden = True
        If Range("B43").Value = 0 Then Range("B44").EntireRow.Hidden = True
        If Range("B44").Value = 0 Then Range("B45").EntireRow.Hidden = True
        If Range("B45").Value = 0 Then Range("B46").EntireRow.Hidden = True
        If Range("B46").Value = 0 Then Range("B47").EntireRow.Hidden = True
            
        If Not Range("B28").Value = 0 Then Range("B29").EntireRow.Hidden = False
        If Not Range("B28").Value = 0 Then Range("B29").EntireRow.Hidden = False
        If Not Range("B29").Value = 0 Then Range("B30").EntireRow.Hidden = False
        If Not Range("B30").Value = 0 Then Range("B31").EntireRow.Hidden = False
        If Not Range("B31").Value = 0 Then Range("B32").EntireRow.Hidden = False
        If Not Range("B32").Value = 0 Then Range("B33").EntireRow.Hidden = False
        If Not Range("B33").Value = 0 Then Range("B34").EntireRow.Hidden = False
        If Not Range("B34").Value = 0 Then Range("B35").EntireRow.Hidden = False
        If Not Range("B35").Value = 0 Then Range("B36").EntireRow.Hidden = False
        If Not Range("B36").Value = 0 Then Range("B37").EntireRow.Hidden = False
        If Not Range("B37").Value = 0 Then Range("B38").EntireRow.Hidden = False
        If Not Range("B38").Value = 0 Then Range("B39").EntireRow.Hidden = False
        If Not Range("B39").Value = 0 Then Range("B40").EntireRow.Hidden = False
        If Not Range("B40").Value = 0 Then Range("B41").EntireRow.Hidden = False
        If Not Range("B41").Value = 0 Then Range("B42").EntireRow.Hidden = False
        If Not Range("B42").Value = 0 Then Range("B43").EntireRow.Hidden = False
        If Not Range("B43").Value = 0 Then Range("B44").EntireRow.Hidden = False
        If Not Range("B44").Value = 0 Then Range("B45").EntireRow.Hidden = False
        If Not Range("B45").Value = 0 Then Range("B46").EntireRow.Hidden = False
        If Not Range("B46").Value = 0 Then Range("B47").EntireRow.Hidden = False
    
    End Sub
    Last edited by JBeaucaire; 07-31-2013 at 12:48 PM. Reason: Added CODE tags, as per Forum Rules. Take a moment to read the Forum Rules in the menu bar above. Thanks.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Unhiding / Hiding rows based on a different cell value
    By gm2612 in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 07-30-2013, 05:15 AM
  2. [SOLVED] Help with hiding or unhiding multiple ranges of rows based on cell value on another sheet
    By Jake Bierly in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-22-2013, 12:14 PM
  3. Hiding and unhiding worksheets based on a cell value from another worksheet
    By J_barber in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-05-2013, 01:02 PM
  4. [SOLVED] Hiding / unhiding pictures based on cell value
    By supern0va in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-14-2012, 12:00 PM
  5. Hiding and Unhiding Entire Columns based on Cell Reference
    By montego in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-02-2010, 01:25 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