Solved

Hide Columns in Excel based on a Cell's Value

Posted on 2014-12-21
7
101 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
[X]
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
  • 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 47

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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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 47

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 47

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

Scamming the Scammers!

Have you ever heard of Scam Baiting?
It's a highly entertaining sport that you can participate in.
Introduction to beating scammers at their own game and how you can help
Share your thoughts, ideas and experiences on the topic.
Links to top Anti-Scam resources provided.

Question has a verified solution.

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

Suggested Solutions

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
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.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

710 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