HIDING A VARIABLE NUMBER OF COLUMNS

  • Thread starter Thread starter ghamilton
  • Start date Start date
G

ghamilton

I have a spreadsheet with 12 columns of numbers preceded by one column
with labels. I want to use the same spreadsheet for each month of
data and just hide the blank columns. Since it is February, I want to
hide the columns for March through December (D through M) since they
will be blank. Next month I only want to hide April through December,
etc.

How can I add a dialog box where I enter the number of the month (in
this case 2) and it hides the rest of the months. Or alternatively,
if I tell it how many columns to hide, it can start at column M and
work backwards.

Thanks,



Columns("D:M").Select
Range("D1").Activate
Selection.EntireColumn.Hidden = True
 
How about something like

Sub HideColumns()

MonthVar = 7

ActiveSheet.Range("B1").Offset(0, MonthVar).Resize(1, 12 -
MonthVar).EntireColumn.Hidden = True


End Sub
I just rezise the range by subtracting the variable from 12 and hide those
columns

Of course you can set an inputbox to the variable or just pull from the
current date

David
 

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

Back
Top