Solved

Hide Columns in Excel based on a Cell's Value

Posted on 2014-12-21
7
97 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
ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

 

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Office 2016 without internet 6 38
VBA Works in Excel 2010 Not 2016 Help! 5 18
how to add loop into this VBA 3 28
Excel error  #DIV/0! 7 18
Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
This article will show you how to use shortcut menus in the Access run-time environment.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
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.

772 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