Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Hiding columns Where Conditional Format was not "activated"

Posted on 2014-01-24
8
239 Views
Last Modified: 2014-01-25
Hi,

I have tried to resolve this but have ended up with "ugly" solutions.

Simple enough to explain.
See attached.

I have a cells in a sheet which will potentially be "coloured" depending on certain conditional formatting.

I want a solution (probably a macro) which simply "hides" any columns where the formatting is not activated.  See my example attached.  If one cell is coloured then the whole column should remain visible - otherwise hide the column

Ideally, (but not mandatory) the solution should not need to examine the actual format rules.  Ideally, the solution would simply KNOW that a cell has been formatted and hence remains visible.
TrafficLightsV1Solved.xlsm
0
Comment
Question by:Patrick O'Dea
8 Comments
 
LVL 50

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 167 total points
ID: 39806238
HI,

you could use Pearson's solution
http://www.cpearson.com/excel/CFColors.htm

Function ActiveCondtion and Function GetStrippedValue used in ActiveCondition

Sub Macro5()
For Each cl In Range("B2:E5").Columns
    If ActiveCondition(Range(Cells(2, cl.Column), Cells(2, cl.Column).End(xlDown))) Then
        cl.EntireColumn.Hidden = True
    Else
        cl.EntireColumn.Hidden = False
    End If
Next
End Sub

Open in new window

Regards
0
 
LVL 33

Assisted Solution

by:Rob Henson
Rob Henson earned 167 total points
ID: 39806250
If you add a couple of rows at the top of the sheet and add these two array formulas, it will count the number of cells that meet the same criteria as the formatting:

Assumed inserted two rows so data now starts at row 3 and formula in row 1
Red =COUNTIF(B4:B15,"<"&TrafficLights!$B2:$B13)
Orange =COUNTIFS(B4:B15,"<"&TrafficLights!$C2:$C13,B4:B15,"=>"&TrafficLights!$B2:$B13)

Confirm these with Ctrl + Shift + Enter and { } brackets will appear at either end of the formula.

You / We can then setup a routine that hides those columns where both are zero.

Thanks
Rob H
0
 

Author Comment

by:Patrick O'Dea
ID: 39806267
Rgonzo,

ActiveCondition
Sub or function not defined??

See attached.
AdctiveCondition.pdf
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 50

Expert Comment

by:Rgonzo1971
ID: 39806269
Hi,

The functions are on the link

Regards
0
 

Author Comment

by:Patrick O'Dea
ID: 39807401
Hi ,

I have loaded Pearsons stuff and it is still not 100%
It deletes 4 of my rows when only 2 have formatting applied.
See attached.

Perhaps I have missed something??

Thanks for your persistence!
0
 

Author Comment

by:Patrick O'Dea
ID: 39807424
Hi ,

I have loaded Pearsons stuff and it is still not 100%

See macro5.
It deletes 4 of my rows when only 2 have formatting applied.
See attached.

Perhaps I have missed something??

Thanks for your persistence!
HideCondits.xlsm
0
 
LVL 81

Accepted Solution

by:
byundt earned 166 total points
ID: 39808089
If you have Excel 2010 or later, you can use the DisplayFormat property of a cell to get the fill color as displayed. This lets you use a very short macro, without need for any of Mr. Pearson's code.
Sub HiddenColors()
Dim cel As Range, col As Range, rg As Range
Dim bColor As Boolean
Application.ScreenUpdating = False
Set rg = ActiveSheet.UsedRange
Set rg = rg.Offset(0, 1).Resize(rg.Rows.Count, rg.Columns.Count - 1) 'All the data except column A
For Each col In rg.Columns
    bColor = False
    For Each cel In col.Cells
        If cel.DisplayFormat.Interior.ColorIndex <> -4142 Then
            bColor = True
            Exit For
        End If
    Next
    col.EntireColumn.Hidden = Not bColor
Next
End Sub

Open in new window

0
 

Author Closing Comment

by:Patrick O'Dea
ID: 39809051
Thanks folks for great responses.

I went with the solution provided by byundt!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question