Consulting

Results 1 to 4 of 4

Thread: Solved: Hiding Columns if all cells = zero

  1. #1

    Solved: Hiding Columns if all cells = zero

    Hi guys, I need some more help please!

    I would like to be able to hide several columns in my spreadsheet if one specific cell in each column = zero

    For example:

    IF W35 = zero then hide the entire column W
    IF X35 = zero then hide the entire column X

    This will be the same for columns W:AI.

    Is this possible?

    Many thanks as always


    Andy

  2. #2
    VBAX Tutor mohanvijay's Avatar
    Joined
    Aug 2010
    Location
    MADURAI
    Posts
    268
    Location
    Hai try this

     
    Dim x As Integer
    x = 22
    For i = 1 To 13
        chk_value = Cells(35, x + i)
        
        If chk_value = 0 Then
        
            Columns(x + i).EntireColumn.Hidden = True
        
        End If
    Next i

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Public Sub Test()
    Dim Lastcol As Long
    Dim i As Long

    With ActiveSheet

    Lastcol = .Cells(1, .Columns.Count).End(xlToLeft).Column
    For i = 1 To Lastcol

    .Columns(i).Hidden = .Cells(35, i).Value2 = 0
    Next i
    End With
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    Perfect - thank you both

Posting Permissions

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