Closed Thread
Results 1 to 2 of 2

I need the hide/unhide code to work with text not only numbers and single column

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-19-2012
    Location
    Croatia
    MS-Off Ver
    Excel 2007
    Posts
    200

    I need the hide/unhide code to work with text not only numbers and single column

    The VBA code below that goes into the worksheet, hides rows that contain 0 or "" blank. And unhides everything else. It works good. However...

    --------------
    FIRST OF ALL:
    It only looks for NUMBERS not text. So, if a cell contains TEXT and not a number, then it is hidden too. But that's not good for me, because I need it to look for both numbers or text. If "" blank then hide, if there is text or numbers then unhide. Help me fix that please!


    
    Option Explicit
     
    Private Sub Worksheet_Activate()
         
        Dim HiddenRow&, RowRange As Range, RowRangeValue&
         
         '*****************************
         '< Set the 1st & last rows to be hidden >
        Const FirstRow As Long = 6
        Const LastRow As Long = 200
         
         '< Set the columns that may contain data >
        Const FirstCol As String = "A"
        Const LastCol As String = "B"
         '*****************************
         
        ActiveWindow.DisplayZeros = False
        Application.ScreenUpdating = False
         
        For HiddenRow = FirstRow To LastRow
             
             'Range of columns
            Set RowRange = Range(FirstCol & HiddenRow & _
            ":" & LastCol & HiddenRow)
             
             'sums the entries in cells in the RowRange
            RowRangeValue = Application.Sum(RowRange.Value)
             
            If RowRangeValue <> 0 Then
                 'there's something in this row - don't hide
                Rows(HiddenRow).EntireRow.Hidden = False
            Else
                 'there's nothing in this row yet - hide it
                Rows(HiddenRow).EntireRow.Hidden = True
            End If
             
        Next HiddenRow
         
        Application.ScreenUpdating = True
         
    End Sub

    -----------------------
    AND SECONDLY:
    It will not allow me to just select Col "A"... I have to have a range like A:B... I managed a way around that, but if the code can be fixed that would be better. What I did is add a new column that is always blank, and hid it....

    When I edit the code to:
         '< Set the columns that may contain data >
        Const FirstCol As String = "A"
        Const LastCol As String = "A"
    Then an error comes up saying:
    "Run-time error '13':
    Type mismatch"


    I'm a layman to coding... So, can you please send me a new code that will work for me?\

    Thank you!
    Last edited by nenadmail; 05-23-2012 at 07:37 AM.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: I need the hide/unhide code to work with text not only numbers and single column

    Also,

    This is a duplicate post and as such does not comply with Rule 5 of our forum rules. This thread will now be closed, you may continue in your other thread.

    Thread Closed.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

Closed Thread

Thread Information

Users Browsing this Thread

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

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