Solved

Hide Columns in Excel based on a Cell's Value

Posted on 2014-12-21
7
94 Views
Last Modified: 2014-12-28
Is there a function or VB Macro language that would update a date as soon as the file is activated and from the date hide and unhide columns in excel.  Basically I need to set a report on a single tab in excel so that only the current day of the week should be active/unhidden to have information entered into it.
SheetExample.xlsx
0
Comment
Question by:NYANBCNY32
  • 3
  • 3
7 Comments
 
LVL 23

Expert Comment

by:Michael74
ID: 40512294
This can be done in VBA but we will need a few more details

Is cell B2 to be updated with Todays date on open
Your example has dates in joined cells, are these the columns you are looking to hide
Do new headers need to be created manually or by the application

Another option here could also be to have a data entry sheet which OnSave inputs the data into a hidden worksheet.
0
 

Author Comment

by:NYANBCNY32
ID: 40512361
Yes, cell B2 will be the space where the date will be updated, so that the cells that are already on the sheet itself will then read and the day of the week that matches the date to unhide and the rest remain hidden.
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40515119
I added this code to the workbook. Since the workbook originally only had dates up to 12/21 I added a few days after that.

Private Sub Workbook_Open()
Dim lngCol As Long

With Sheets("Sheet1")
    For lngCol = 3 To ActiveSheet.UsedRange.Columns.Count Step 3
        If .Cells(1, lngCol) <> .Range("B2") Then
            Cells(1, lngCol).EntireColumn.Hidden = True
            Cells(1, lngCol + 1).EntireColumn.Hidden = True
            Cells(1, lngCol + 2).EntireColumn.Hidden = True
        End If
    Next
End With

End Sub

Open in new window

Q-28585055.xlsm
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:NYANBCNY32
ID: 40520928
Thank you Martin Liss for this, just one adjustment and it's my fault on how the sample was posted, the dates start at column E and are 6 columns combined, can the formula change to start at column E and keep all six columns, right now it only holds 3.  Thank you.
Q-28585055--1-.xlsm
0
 
LVL 45

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 40520995
Here you go. Please don't forget to accept my answer if it's correct.
Q-28585055--1-.xlsm
0
 

Author Closing Comment

by:NYANBCNY32
ID: 40521106
PERFECT! Thank you again for the help on this.
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40521123
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now