Results 1 to 5 of 5

hide columns if they are empty populated from userform

Threaded View

  1. #1
    Forum Contributor
    Join Date
    02-19-2013
    Location
    UK
    MS-Off Ver
    Excel 2019
    Posts
    677

    hide columns if they are empty populated from userform

    Hi all,
    Following code works fine. It will hide column if row 2 is empty ( But only for data in row 2 of the respective columns)
    How do I get it it work for the entire columns?
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        If Range("J2").Value = "" Then
            Columns("J").EntireColumn.Hidden = True
        Else
            Columns("J").EntireColumn.Hidden = False
        End If
    If Range("H2").Value = "" Then
            Columns("H").EntireColumn.Hidden = True
        Else
            Columns("H").EntireColumn.Hidden = False
        End If
    If Range("I2").Value = "" Then
            Columns("I").EntireColumn.Hidden = True
        Else
            Columns("I").EntireColumn.Hidden = False
        End If
    If Range("K2").Value = "" Then
            Columns("K").EntireColumn.Hidden = True
        Else
            Columns("K").EntireColumn.Hidden = False
        End If
    
    If Range("L2").Value = "" Then
            Columns("L").EntireColumn.Hidden = True
        Else
            Columns("L").EntireColumn.Hidden = False
        End If
    
    If Range("M2").Value = "" Then
            Columns("M").EntireColumn.Hidden = True
        Else
            Columns("M").EntireColumn.Hidden = False
        End If
    If Range("F2").Value = "" Then
            Columns("F").EntireColumn.Hidden = True
        Else
            Columns("F").EntireColumn.Hidden = False
        End If
    If Range("G2").Value = "" Then
            Columns("G").EntireColumn.Hidden = True
        Else
            Columns("G").EntireColumn.Hidden = False
        End If
    If Range("N2").Value = "" Then
            Columns("N").EntireColumn.Hidden = True
        Else
            Columns("N").EntireColumn.Hidden = False
        End If
    
    
    End Sub
    Test file is attached
    Need some help please
    Kind regards
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Hide empty columns Toggle
    By gherzberg in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-05-2012, 04:15 PM
  2. [SOLVED] Hide empty rows of shown columns
    By wilco in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-17-2012, 05:42 PM
  3. VBA code to hide empty columns.
    By ms_ex_novice in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-29-2011, 10:43 AM
  4. [SOLVED] Un hide non empty columns
    By hamad.fatima@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-07-2006, 03:28 AM
  5. Un hide non empty columns
    By hamad.fatima@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-06-2006, 04:39 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1