Assistance for VBA code to hide Column C and filter Column D

brianv

Board Regular
Joined
Dec 11, 2003
Messages
106
I have a parts list and i need a method to hide Column C and filter Column D5 and below (my quantities are entered in Column D) upon clicking cell B3.

Then upon clinking again cell B3, re-show (un-filter) all columns and rows.

I have something already similar in for another worksheet.... but i cant recall how to make work on multiple columns:

This one works by clinking in C3 to filter Column B only, and then by clicking again in C3, will unfilter. There is no physical button in the cell.
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Const COL_VISIBLE = 10
    Const COL_HIDDEN = 0
    Dim lngCol As Long, _
        lngRow As Long, _
        i As Long
 
    'ignore clicks outside the target range
    If Intersect(Target, Range("C3")) Is Nothing Then Exit Sub
    lngCol = Target.Column
    lngRow = Range("C65536").End(xlUp).Row
 
    'show and hide columns and rows
    If Cells(1, lngCol).Value = "Show" Then
        For i = 2 To 2
            Columns(i).ColumnWidth = COL_VISIBLE
            ActiveSheet.AutoFilterMode = False
            Cells(1, lngCol).ClearContents
        Next i
    Else
        For i = 2 To 3
            If i = lngCol Then
                Columns(i).ColumnWidth = COL_VISIBLE
                Cells(1, lngCol).Value = "Show"
            Else
                Columns(i).ColumnWidth = COL_HIDDEN
            End If
            'With Range(Cells(5, lngCol), Cells(lngRow, lngCol))
            With Range("B3:B" & lngRow)
                .AutoFilter
                .AutoFilter Field:=1, Criteria1:="<>"
            End With
        Next i
    End If
End Sub

what do I modify to make this occur... this original code was written in 2006.

Thanks
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Forum statistics

Threads
1,214,905
Messages
6,122,178
Members
449,071
Latest member
cdnMech

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top