tags:

views:

53

answers:

3

I know of several approaches using a macro (VBA) to show/hide columns and rows in Excel, but I cannot figure out or find a way to do this using either a formula or conditional formatting. Of particular interest is Excel 2007 - but I'd be curious to know if someone has managed to do it in any version of Excel.

For those who want background, I have a spread of data with dates across the top and labels down the first column. I would like to specify a date window (on another sheet) as two cells with drop down dates (months) which would then show/hide the appropriate columns on the data sheet.

A: 

sorry, not going to happen without VBA. (But someone prove me wrong)

guitarthrower
i agree with the sentiment ;-) but fingers crossed for smarter people than I!
AJ
+1  A: 

This isn't an answer to your question directly (I strongly doubt there is one), but if you organised your data using a data table, making data go downwards rather than horizontally like a simple OLAP cube, you could probably add a criteria column that checks if the data points are between your two thresholds, and then organise your view in a pivot table.

Combining lists and tables like this is really powerful if you don't like VBA, but VBA really is the solution for this sort of stuff unfortunately.

Andrew
+1 for the comment. I agree, lists and tables are powerful options. I wouldn't normally try to do this in just Excel, but it was a client requirement.
AJ
I'm going to accept your response as i agree there is probably no way to really do this - and looking at the point of spreadsheet technology there is no real reason why there should be. Thanks again.
AJ
+2  A: 

You probably need a third sheet (or use the second sheet where you're speciyfing the dates), and use HLOOKUPS or MATCH functions.

1) Use a function to dynamically populate the column headings you need, based on your date range. So in B1 you'd put =StartDate

2) cell C1 would be =IF(B1+1<=EndDate,B1+1,"") and copy across a suitable number of columns, based on your assessment of how long a period people are likely to look for

3) Cells B2 down and right would then use your preference of either an HLOOKUP() or OFFSET(MATCH()) combination, in conjunction with an IF to determine whether you want it. e.g. B2 would be =IF(B$1<>"",HLOOKUP(B$1,DataRange,row(B2),false),"") and copy down and across as needed.

However the suggestion above about transposing the data and then using a PivotTable, with the aid of a helper column alongside your data (i.e. IF(AND(date>=StartDate,date<=EndDate),"Show","Hide") and then filter on the "Show" in the page field.

Diem
+1 Nice take on the problem - a variable view window derived from the data itself. I actually ended up using a hybrid of your and Andrew's suggestions.
AJ