Results 1 to 7 of 7

Thread: Hide columns that contain 0 value

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    623
    Location
    Paste the following into a regular module :

    Option Explicit
    
    'If the entire Column is empty :
    Sub HideCol()
        Dim N As Long, wf As WorksheetFunction, M As Long
        Dim i As Long, j As Long
        N = Columns.Count
        M = Rows.Count
        Set wf = Application.WorksheetFunction
        Application.ScreenUpdating = False
        For i = 26 To 1 Step -1 '<<<---------------------------- Change 26 (Col Z) to reflect max columns possible
            If wf.CountBlank(Columns(i)) <> M Then Exit For
        Next i
        For j = i To 1 Step -1
            If wf.CountBlank(Columns(j)) = M Then
                Cells(1, j).EntireColumn.Hidden = True
            End If
        Next j
        Application.ScreenUpdating = True
    End Sub
    Create a command button that is attached to the above macro.
    Attached Files Attached Files
    Last edited by Aussiebear; 04-03-2025 at 01:51 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •