Forum Discussion

JShearer98's avatar
JShearer98
Copper Contributor
Sep 09, 2025
Solved

Macro to filter table to a searched result, then hide columns that contain a blank or a set value.

Hi All,   I'm trying to figure out how to do the above. Essentially I have a list of assemblies and along the same row is a list of each part within that assembly. Not every sub-part is used in eac...
  • HansVogelaar's avatar
    Sep 09, 2025

    Does this do what you want?

    Sub SEARCH()
        Dim rng As Range
        Application.ScreenUpdating = False
        Range("B2:W2").EntireColumn.Hidden = False
        If Range("B2") <> "" Then
            Range("B5").AutoFilter Field:=1, Criteria1:=Range("B2").Value
            On Error Resume Next
            Set rng = Range("B" & Rows.Count).End(xlUp).Resize(1, 22).SpecialCells(xlCellTypeBlanks)
            On Error GoTo 0
            If Not rng Is Nothing Then
                rng.EntireColumn.Hidden = True
            End If
        End If
        Application.ScreenUpdating = True
    End Sub

     

Resources