PDA

View Full Version : Solved: Hide Columns Form



bujaman
05-27-2008, 08:42 AM
I am working on a form and needed some help. Most of the code is in place and working, however, I can't get one part to function like I would like. I have a button on a sheet that opens a userform. On the form there is a place where the user can hide all the rows that are blank in a certain column (working great), and a text field poplulated with dates from the headings of columns. I want people to be able to select the dates they want to hide. Right now it is sort of working. I can select a date and it will hide columns, but not the right ones. If I select the first date on the list, it hides column A, not columns H and I like I would like. Yes, I would like it to hide both columns because the data that needs to be shown/hidden spans two adacent columns. Any help would be greatly appreciated. I attached an example file of what I have so far. Thanks again for any help.

Bob Phillips
05-27-2008, 08:58 AM
Private Sub CommandButton5_Click()
Dim colrange As Range

ColCnt = 0
For r = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(r) Then
ColCnt = Application.Match(CLng(CDate(ListBox1.List(r))), ActiveSheet.Rows(7), 0)

If colrange Is Nothing Then
Set colrange = ActiveSheet.Columns(ColCnt).Resize(, 2)
Else
Set colrange = Union(colrange, ActiveSheet.Columns(ColCnt).Resize(, 2))
End If
End If
Next r

If Not colrange Is Nothing Then colrange.EntireColumn.Hidden = True

End Sub

bujaman
05-27-2008, 09:46 AM
Thanks! It works perfectly.