Hide Column - With text in cell

O

O&O

How can I make this macro work if my cells contain a text e.g AAA
instead of 0 & work on Sheet1, Sheet2 & Sheet3

Sub Test1()
Dim cell As Range
For Each cell In Range("c1:j1")
If cell.Value <> 0 Then
cell.EntireColumn.Hidden = True
End If
Next cell
End Sub

Thxs
 
B

Bob Phillips

Sub Test1()
Dim cell As Range
For Each cell In Range("c1:j1")
If cell.Value <> "AAA" Then
cell.EntireColumn.Hidden = True
End If
Next cell
End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)
 
O

O&O

Thxs - but how about Sheet1 &Sheet2 &Sheet3
thxs
Bob said:
Sub Test1()
Dim cell As Range
For Each cell In Range("c1:j1")
If cell.Value <> "AAA" Then
cell.EntireColumn.Hidden = True
End If
Next cell
End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)
 
B

Bob Phillips

Sorry, didn't realise you want that included in the code

Sub Test1()
Dim cell As Range
Dim arySheets
Dim sh As Worksheet

arySheets = Array("Sheet1", "Sheet2", "Sheet3")
For Each sh In Worksheets(arySheets)
For Each cell In sh.Range("c1:j1")
If cell.Value <> "AAA" Then
cell.EntireColumn.Hidden = True
End If
Next cell
Next sh
End Sub




--

HTH

RP
(remove nothere from the email address if mailing direct)
 
A

al007

thxs!!!
Bob said:
Sorry, didn't realise you want that included in the code

Sub Test1()
Dim cell As Range
Dim arySheets
Dim sh As Worksheet

arySheets = Array("Sheet1", "Sheet2", "Sheet3")
For Each sh In Worksheets(arySheets)
For Each cell In sh.Range("c1:j1")
If cell.Value <> "AAA" Then
cell.EntireColumn.Hidden = True
End If
Next cell
Next sh
End Sub




--

HTH

RP
(remove nothere from the email address 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

Top