+ Reply to Thread
Results 1 to 3 of 3

Hide non adjacent columns if all cell value is blank

  1. #1
    Registered User
    Join Date
    09-07-2012
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2010
    Posts
    1

    Smile Hide non adjacent columns if all cell value is blank

    I have a worksheet where I need to look at column and if the column is blank, I need to hide that column and another non adjacent column (example column C ="", then hide entire column C and I). I need to do this with four columns ( C, D, E, and F). If one of the four columns mentioned has contents I would need to leave that column unhidden along with its non adjacent column.


    Below is what I have for VBA code, but it only seems to review column C and then stops.

    If Application.WorksheetFunction.CountA(Range("C2" & FinalRow)) = "" Then
    Columns("C").EntireColumn.Hidden = True
    Columns("I").EntireColumn.Hidden = True

    If Application.WorksheetFunction.CountA(Range("D2" & FinalRow)) = "" Then
    Columns("D").EntireColumn.Hidden = True
    Columns("J").EntireColumn.Hidden = True

    If Application.WorksheetFunction.CountA(Range("E2" & FinalRow)) = "" Then
    Columns("E").EntireColumn.Hidden = True
    Columns("K").EntireColumn.Hidden = True

    If Application.WorksheetFunction.CountA(Range("F2" & FinalRow)) = "" Then
    Columns("F").EntireColumn.Hidden = True
    Columns("L").EntireColumn.Hidden = True

    End IF

  2. #2
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Hide non adjacent columns if all cell value is blank

    If you want it to eveluate all IF statements then you need to put an EndIf after each if statement.

    The way I understand it, the if statement looks for ONE true IF then completes it and goes to END IF.

    Please Login or Register  to view this content.
    Please ensure you mark your thread as Solved once it is. Click here to see how.
    If a post helps, please don't forget to add to our reputation by clicking the star icon in the bottom left-hand corner of a post.

  3. #3
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Hide non adjacent columns if all cell value is blank

    I don't think this "("C2" & FinalRow)" is going to do what you want or think it is going to do.

    You might mean this ("C2:C" & FinalRow)

    In addition. The worksheet function is going to return a number not a string. "" won't work.

    Maybe this:

    Please Login or Register  to view this content.
    Last edited by stnkynts; 04-09-2014 at 06:21 PM.

+ 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] Filtering Columns when some adjacent columns are blank
    By rg1954 in forum Excel General
    Replies: 5
    Last Post: 04-16-2013, 10:00 AM
  2. Hide columns if all cells are blank or £0.00
    By Atticgirl in forum Excel General
    Replies: 9
    Last Post: 07-21-2011, 08:44 AM
  3. Hide blank columns via loop
    By SunOffice in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-09-2011, 10:17 PM
  4. Hide/unhide non adjacent columns
    By nigelog in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-12-2008, 09:05 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