View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Todd[_5_] Todd[_5_] is offline
external usenet poster
 
Posts: 28
Default macro to hide column based on header

Thanks for the help. I used what you gave me and came up
with this. But its not quite right. the Inactive macro
hides columns A:J No matter what?

The XXX macro doesn't work at all yet.
I am learning but slow! Can you see where I went wrong?


Todd


Sub HideInactive()

For Each c In Worksheets(1).Range("A1:J10")
If c.Value = Inactive Then
c.EntireColumn.Select
Selection.EntireColumn.Hidden = True

End If
Next c

End Sub

Sub HideXXX()
For Each c In Selection
If c.Value = "x*" Then c.EntireRow.Select
Selection.EntireRow.Hidden = True

Next c

End Sub

-----Original Message-----
This checks the value for all cells in the range A1
through J10 and if any of the values are equal to XXX it
hides the column. Just change the value of the Range and
you can also replace Worksheets(1) with Worksheets
("Sheet_Name").... Hope this is what you are looking for.


Sub HideInactive()

For Each c In Worksheets(1).Range("A1:J10")
If c.Value = "XXX" Then
c.EntireColumn.Select
Selection.EntireColumn.Hidden = True

End If
Next c

End Sub





-----Original Message-----
I've been using auto filter to hide unwanted columns and
rows. I tried recording that as a macro but it is

doesn't
work to well. I need a better macro that would hide
columns where the header is "Inactive" or the row
contains "XXX". Can anyone help?


Todd
.

.