Question

Locked

Using Visual Basic in Excel to hide columns

By Allan.Thompson@ntlworld ·
Hi there,

I am having a bad day...
I am trying to hide columns on a worksheet ("Fixtures") by clicking a checkbox on "Data" sheet. But it doesn't work! Seems fairly simple... but nothing happens when I check the box and I am stuck!

I have the code:-

Private Sub CheckBox1_Click()

Call sheetsunprotect: ' goto subroutine to unprotect all sheets and disable updating

' box checked
If CheckBox1.Value = True Then
' Code to hide data.
Worksheets("Fixtures").Select
Columns("R:T").Hidden = True
End If

'box unchecked
If CheckBox1.Value = False Then
' Code to unhide data.
Worksheets("Fixtures").Select
Columns("R:T").Hidden = False
End If

Call sheetsprotect: ' goto subroutine to protect all sheets and disable updating

' go back to "Data" sheet
Worksheets("Data").Select

End Sub

Can anyone help?

Allan

This conversation is currently closed to new comments.

3 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

With...

Seems like I had to use a With command instead....

Private Sub CheckBox1_Click()

Call sheetsunprotect: ' goto subroutine to unprotect all sheets and disable updating

' box checked
If CheckBox1.Value = True Then
' Code to hide "For", "Against" and "Difference" data.
Worksheets("Fixtures").Select
With ActiveSheet
.Range("R1,T1").EntireColumn.Hidden = True
End With
End If

'box unchecked
If CheckBox1.Value = False Then
' Code to unhide "For", "Against" and "Difference" data.
Worksheets("Fixtures").Select
With ActiveSheet
.Range("R1,T1").EntireColumn.Hidden = False
End With
End If

Call sheetsprotect: ' goto subroutine to protect all sheets and enable updating

' go back to "Data" sheet
Worksheets("Data").Select

End Sub

Allan

Collapse -

It works

by tarunpatkar In reply to Using Visual Basic in Exc ...

Thanks alot sir, its working.

Back to Software Forum
3 total posts (Page 1 of 1)  

Software Forums