Unhide columns

C

Chris

Good morning,

Is there a way to do this: Have a list box that contains
the names of columns on your spreadsheet. Also have a
checkbox beside each column name. Once a name is
checked, it unhides that column only?

thanks in advance.
Chris
 
D

Dave Peterson

I used a listbox from the control toolbox toolbar and placed it on the
worksheet.

I added this event to that worksheet's code module:

Private Sub Worksheet_Activate()
With Me.ListBox1
.MultiSelect = fmMultiSelectMulti
.ListStyle = fmListStyleOption
.ListFillRange = Me.Range("K1:k6").Address(external:=True)
End With
End Sub

(I had the names of the columns in K1:k6. I used ColA, ColB, ColC...)

Then in the same module, I had this code for when I clicked on one of the
listbox items:

Option Explicit
Private Sub ListBox1_Change()
Dim iCtr As Long
Dim testRng As Range

With Me.ListBox1
For iCtr = 0 To .ListCount - 1
Set testRng = Nothing
On Error Resume Next
Set testRng = Me.Range(.List(iCtr))
On Error GoTo 0
If testRng Is Nothing Then
'Beep Range name not found
Else
testRng.EntireColumn.Hidden = .Selected(iCtr)
End If
Next iCtr
End With
End Sub
 

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