Hide Columns Based on Condition

  • Thread starter Thread starter Skornia115
  • Start date Start date
S

Skornia115

New to VBA and need help.

I am trying to hide columns based on a condition. My workbook has
numerous worksheets. Each worksheet contains data for a specific
"account" and each column within the "account" worksheet has month end
data. Therefore row 1 of each worksheet contains month-end values and
each row below has various data for that specific "account."
Furthermore, the first worksheet, which basically serves as a "menu",
has a cell with a specific date. What I would like to do is write a
macro in each worksheet representing an "account" that hides all
columns in the "account" worksheets that have not occurred yet. (i.e.
If the date on the menu worksheet is 3/31/05, I would like all columns
that have month-end values exceeding 3/31/05 to be hidden). Any
suggestions?
 
For Each sh In Activeworkbook.Worksheets
With sh
If sh.Name <> "Menu" Then
For i = 1 To sh.Cells(1,sh.Columns.Count).End(xlUp).Column
If sh.Cells(1,i).Value >
Worksheets("Menu").Range("A1").Value Then
Columns(i).Hidden = True
End If
Next i
End If
End With
Next sh

where A1 on Menu is the menu date comparing against

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)
 

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