+ Reply to Thread
Results 1 to 4 of 4

Automatically hide/unhinde rows in columns

  1. #1
    Registered User
    Join Date
    03-20-2012
    Location
    Massachusetts
    MS-Off Ver
    Excel 2007
    Posts
    2

    Automatically hide/unhinde rows in columns

    I have a worksheet that I need to hide rows and columns based on a source file. I would like it to automatically happen each time the file is opened. I am currently using this code but it only updates the columns, I then have to go in and run the second part.

    Private Sub Worksheet_Calculate()

    Dim ThisCell As Range

    Application.ScreenUpdating = False

    For Each ThisCell In Range("C2503:AZ2503")
    If ThisCell.Value = 0 Then
    ThisCell.EntireColumn.Hidden = True
    Else
    ThisCell.EntireColumn.Hidden = False

    End If

    Next ThisCell

    End Sub

    Private Sub Worksheet_Calculate2()

    Dim ThatCell As Range

    Application.ScreenUpdating = False

    For Each ThatCell In Range("B100:b2501")
    If ThatCell.Value = 0 Then
    ThatCell.EntireRow.Hidden = True
    Else
    ThatCell.EntireRow.Hidden = False
    End If

    Next ThatCell

    End Sub

  2. #2
    Valued Forum Contributor marreco's Avatar
    Join Date
    07-02-2011
    Location
    Brazil
    MS-Off Ver
    Excel 2010
    Posts
    1,862

    Re: Automatically hide/unhinde rows in columns

    Put your code around tags

    Try..Ptu in ThisWorkbook

    Please Login or Register  to view this content.
    "No xadrez nem sempre a menor dist?ncia entre dois pontos ? uma linha reta" G. Kasparov.

    If your problem is solved, please say so clearly, and mark your thread as Solved: Click the Edit button on your first post in the thread, Click Go Advanced, select b from the Prefix dropdown, then click Save Changes. If more than two days have elapsed, the Edit button will not appear -- ask a moderator to mark it.

  3. #3
    Registered User
    Join Date
    03-20-2012
    Location
    Massachusetts
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Automatically hide/unhinde rows in columns

    I am a novice at this so I'm not sure what put your code around tags mean. I did go back and change the code to this

    Private Sub Workbook_Open()

    Dim ThisCell As Range
    Dim ThatCell As Range

    Application.ScreenUpdating = False

    For Each ThisCell In Range("C2503:AZ2503")
    If ThisCell.Value = 0 Then
    ThisCell.EntireColumn.Hidden = True
    Else
    ThisCell.EntireColumn.Hidden = False

    End If

    Next ThisCell

    For Each ThatCell In Range("B100:b2501")
    If ThatCell.Value = 0 Then
    ThatCell.EntireRow.Hidden = True
    Else
    ThatCell.EntireRow.Hidden = False
    End If


    Next ThatCell

    End Sub

    But it still requires me to manually run the code to work. I would think that by using Sub Workbook_Open would generate the code automatically? Any help would be appreciated

  4. #4
    Valued Forum Contributor marreco's Avatar
    Join Date
    07-02-2011
    Location
    Brazil
    MS-Off Ver
    Excel 2010
    Posts
    1,862

    Re: Automatically hide/unhinde rows in columns

    Try the event Private Sub Worksheet_Change (ByVal Target As Range)

    Please read the forum rules.

+ Reply to 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