Solved

Hide Columns in Excel based on a Cell's Value

Posted on 2014-12-21
7
95 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 46

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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 46

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 46

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Outlook Free & Paid Tools
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

863 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

27 Experts available now in Live!

Get 1:1 Help Now