Macro that will always hide / unhide next column

K

Kirby

Thank you in advance for your help; it is much appreciated. I have a
weekly sales tracking spreadsheet that always shows the current week
and previous 3 weeks sales data. Currently I have 52 columns, one for
each week. Only the current week and previous 3 weeks are visible,
the other columns are hidden. Therefore, there are hidden columns
left of the first visible week and hidden columns right of the last
visible week.

Example:
May-12 May-19 May-26 Jun-2

717 711 721 721
92 86 92 92

I have created 2 macros; one that will unhide the colunm to the right
of the active cell:
ActiveCell.Offset(0, 1).EntireColumn.Hidden = False

and one that will hide the column to the left of the active cell:

ActiveCell.Offset(1, 0).EntireColumn.Hidden = True

My current process involves putting the cursor on the last visible
week and executing the unhide macro and then putting the cursor on the
second week and executing the hide macro. This is working fine, but
is time consuming.

Is there a way to create a macro that will always unhide the next
hidden column and hide the first unhidden column without putting the
cursor in the cells?
 
T

Tom Ogilvy

Sub Managecolumns()
Dim i As Long
For i = 1 To 52
If Columns(i).Hidden = False Then
bfirst = True
Columns(i).Hidden = True
Columns(i + 4).Hidden = False
Exit For
End If
Next
End Sub
 
M

Matt Kirby

Thank you for your code example; it was very helpfull. How would I
manipulate the code to unhide 2 rows instead of one.

Here is a reference to the example code:

Sub Managecolumns()
Dim i As Long
For i = 1 To 52
If Columns(i).Hidden = False Then
bfirst = True
Columns(i).Hidden = True
Columns(i + 4).Hidden = False
Exit For
End If
Next
End Sub

Thank you for your help,

Kirby

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top