View Single Post
  #5   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

Sorry for being so dumb,

I have the macro working but it only hides the first
column where "Inactive" occurs. I changed it a little to
make it search cells I select. All the cells should be in
the 10th row but this way I know for sure. I have been
looking through macro's listed here but I don't see why I
don't hide more than the first "Inactive" it hits.

Thanks again,


Todd


Sub HideInactive()

For Each c In Selection
Inactive = "INACTIVE"
If UCase(c.Value) = Inactive Then
c.EntireColumn.Hidden = True
End If
Next c

End Sub


-----Original Message-----
Thanks!!!!

Todd

-----Original Message-----

Searching for the string Inactive in the top row?

Sub HideInactive()

For Each c In Worksheets(1).Range("A1:J10")
InActive = "INACTIVE"
If Ucase(c.Value) = Inactive Then
c.EntireColumn.Hidden = True
End If
Next c

End Sub

As you had it written, inactive was a variable with no

value. All empty
cells in the first row would have their column hidden.

Use Ucase to make it
case insensitive.

Sub HideXXX()
For Each c In Selection
If Left(lcase(c.Value),1) = "x" Then
c.EntireRow.Hidden = True
Next c

End Sub

Equality doesn't work with a wildcard. If you want to

check the if the
first letter is x, then extract the first letter with

the
LEFT command and
compare it. Use lcase to make the check case

insensitive.

--
Regards,
Tom Ogilvy




Todd wrote in message
...
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
.

.



.

.