Hide Columns Macro

SoulSeeker

New Member
Joined
Feb 26, 2011
Messages
12
Hello,

I'm looking for some help with a macro code. I need to hide columns depending on the actual time. Here's what i have:

<table border="1"><tbody><tr><td>08:00</td><td>09:00</td><td>10:00</td><td>11:00</td><td>12:00</td><td>13:00</td></tr></tbody></table>

And so on, and depending on the actual time i want to hide the rest of the columns. If for example the actual time is 10:30 AM i want to hide column D, E and F. Any help would be greatly appreciated. Thanks :)
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hello,

I'm looking for some help with a macro code. I need to hide columns depending on the actual time. Here's what i have:

<table border="1"><tbody><tr><td>08:00</td><td>09:00</td><td>10:00</td><td>11:00</td><td>12:00</td><td>13:00</td></tr></tbody></table>

And so on, and depending on the actual time i want to hide the rest of the columns. If for example the actual time is 10:30 AM i want to hide column D, E and F. Any help would be greatly appreciated. Thanks :)

Maybe something like this?

Code:
Sub SoulSeeker()

'If Range("A1") holds the time value NOW

Select Case Range("A1").Value

Case Is = #10:00:00 AM#

    Cells.Columns.Hidden = False
    Columns("A:A").Hidden = True
    
Case Is = #10:30:00 AM#

    Cells.Columns.Hidden = False
    Columns("D:F").Hidden = True
    
End Select


End Sub
 
Upvote 0
Or this...assuming your column headers are in row 1
Code:
Sub hideme()
Dim c As Range
Dim MyTime As Long
MyTime = Format(Hour(Now()), "####")
For Each c In Range("A1:H1")
    If Format(Hour(c), "####") > MyTime Then
    c.EntireColumn.Hidden = True
    End If
Next c
End Sub
 
Upvote 0
I like that one jmthompson, it actually works perfectly. The issue is that i want to hide columns using that as a reference. So i have the hours of the day in range AA2:AQ2 because I'm doing calculations that require to have them in a single row, but what i really want to hide is what is what is on D1:S1 based on the actual time.
 
Upvote 0

Forum statistics

Threads
1,224,524
Messages
6,179,308
Members
452,904
Latest member
CodeMasterX

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