Unhiding next column

stroffso

Board Regular
Joined
Jul 12, 2016
Messages
160
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have a master sheet with Columns dated across starting from 01/07/16 in Cell B1, 02/07/16 in Cell C1 and so on across.

I have charts that are connected with the master sheet and I want it to update each day with only data that is entered so that the charts arent showing loads of empty data. For this reason I have Columns after today hidden, so each day i have to unhide all columns and then hide them again when I am finished.

There are 2 questions here:
Is there any easier way of doing this?
If no to the above is there some code that will unhide all columns and then hide all after todays date?

Sorry if my explanation is poor but would really appreciate any help with this,

thanks
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Put this in the Workbook_ Open Event in the VBE

Code:
Option Explicit


Private Sub Workbook_Open()
    Dim lc As Long
    lc = Cells(1, Columns.Count).End(xlUp).Column
    Dim i As Long
    For i = 2 To lc
        If Cells(1, i) > Date Then
            Columns(i).Hidden = True
        Else: Columns(i).Hidden = False
        End If
    Next i
End Sub
 
Upvote 0
Thanks for that, It doesnt seem to work though as I need it specifically for one tab. Is there an option to specify the tab and then run the code? Also when you say put in the Workbook_Open Event where is this located?

Put this in the Workbook_ Open Event in the VBE

Code:
Option Explicit


Private Sub Workbook_Open()
    Dim lc As Long
    lc = Cells(1, Columns.Count).End(xlUp).Column
    Dim i As Long
    For i = 2 To lc
        If Cells(1, i) > Date Then
            Columns(i).Hidden = True
        Else: Columns(i).Hidden = False
        End If
    Next i
End Sub
 
Upvote 0
Hi stroffso,
the workbook Open Event is locatd in your VBE Editor.. douple click on ThisWorkbook I guess it is called...
When you double click on it it automatically opens that event.

HTH
 
Upvote 0
What a very silly question on my part, thanks for clarifying and thanks for original answer too alansidman
Hi stroffso,
the workbook Open Event is locatd in your VBE Editor.. douple click on ThisWorkbook I guess it is called...
When you double click on it it automatically opens that event.

HTH
 
Upvote 0
Which worksheet do you want this to occur in when you open the workbook?
 
Upvote 0
The worksheet is called "Difference Consolidated"

On that sheet I have columns going across for each day of the year showing data relating to that day. I also have charts on another sheet relating to the difference consolidated sheet. So that the charts only show the relevant data up to and including today I hide all the future dated columns. So each day I just need to unhide one of the columns if that makes sense?
thanks

Which worksheet do you want this to occur in when you open the workbook?
 
Upvote 0
Code:
Option Explicit


Private Sub Workbook_Open()
    With Sheets("Difference Consolidated")
    Dim lc As Long
    lc = Cells(1, Columns.Count).End(xlUp).Column
    Dim i As Long
    For i = 2 To lc
        If Cells(1, i) > Date Then
            Columns(i).Hidden = True
        Else: Columns(i).Hidden = False
        End If
    Next i
    End With
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top