Hiding Columns help !

S

Steve

HYCH

Have Columns of Data in a spreadsheet, Column D (4) is the starting
column and Column AX (50) has the last of the data, these cells in
this range contain single letters denoting a shift worked, have what i
thought would enable me to hide columns that were differents letters
and only display the ones that had the letter "A" in them, but get
error.

Works fine if i am hiding rows with some changes to it, ie beginrow
rather than beginCol, any help would be appreciated.

Sub TextBox3_Click()
Application.ScreenUpdating = False
beginCol = 4
EndCol = 50
ChkRow = 2
For ColCnt = beginCol To EndCol
If Cells(ColCnt, ChkRow).Text <> "a" Then
Cells(ColCnt, ChkRow).EntireCol.Hidden = True
Else
Cells(ColCnt, ChkRow).EntireCol.Hidden = False
End If
Next ColCnt
Application.ScreenUpdating = True
End Sub



Steve
 
D

Don Guillett

Modify this idea to suit such as
for i=50 to 4 step -1

Sub hidecolsifnota()
For i = Cells(2, Columns.Count).End(xlToLeft).Column To 1 Step -1
If LCase(Cells(2, i)) <> "a" Then Columns(i).Hidden = True
Next i
End Sub
 
J

Jim Rech

Cells(ColCnt, ChkRow).Text

The row number should be first.

--
Jim
| HYCH
|
| Have Columns of Data in a spreadsheet, Column D (4) is the starting
| column and Column AX (50) has the last of the data, these cells in
| this range contain single letters denoting a shift worked, have what i
| thought would enable me to hide columns that were differents letters
| and only display the ones that had the letter "A" in them, but get
| error.
|
| Works fine if i am hiding rows with some changes to it, ie beginrow
| rather than beginCol, any help would be appreciated.
|
| Sub TextBox3_Click()
| Application.ScreenUpdating = False
| beginCol = 4
| EndCol = 50
| ChkRow = 2
| For ColCnt = beginCol To EndCol
| If Cells(ColCnt, ChkRow).Text <> "a" Then
| Cells(ColCnt, ChkRow).EntireCol.Hidden = True
| Else
| Cells(ColCnt, ChkRow).EntireCol.Hidden = False
| End If
| Next ColCnt
| Application.ScreenUpdating = True
| End Sub
|
|
|
| Steve
 

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