+ Reply to Thread
Results 1 to 4 of 4

VBA code to hide rows doesn't work across multiple tabs

  1. #1
    Registered User
    Join Date
    06-18-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    4

    VBA code to hide rows doesn't work across multiple tabs

    Hi
    I'm new to VBA and have managed to cobble this code together thanks to a bit of googling.
    Private Sub Workbook_Open()

    BeginRow = 8
    EndRow = 10
    ChkCol = 5
    ChkCol6 = 6

    For RowCnt = BeginRow To EndRow
    If Cells(RowCnt, ChkCol).Value = "0" And _
    Cells(RowCnt, ChkCol6).Text = "-" Then
    Cells(RowCnt, ChkCol).EntireRow.Hidden = True
    Else
    Cells(RowCnt, ChkCol).EntireRow.Hidden = False
    End If
    Next RowCnt

    End Sub
    I thought it was doing what I want but I've realised it isn't working on all tabs of a spreadsheet, only the tab that is active when the spreadsheet opens. It's saved on 'This Workbook', not an individual sheet.

    I don't really know what I'm doing so I'm not sure what I need to add to my code to make it work on all of the tabs. Everyone's code is different so Googling only gets me so far.

    Any help would be much appreciated.
    Last edited by jfjfuweo; 02-20-2020 at 08:47 AM.

  2. #2
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Re: VBA code to hide rows doesn't work across multiple tabs

    Hi there,
    Can you please let us know how many sheets you have and how many of them do you need the columns to be hidden?
    Are the same columns on all sheets the same to be hidden? If so, let us know the columns name (e.g. "column B; Column C to F, etc).
    When do you want the code to work? When the workbook is open? When it closes? Or you want a button that hides and unhides the sheets as you want?
    Cheers,
    Filipe


    * If a reply solved or answered your query/question, you can add reputation to the person by clicking on the * Add Reputation
    * When question is resolved, please mark your thread as SOLVED


    Thanks and regards,
    Filipe Oliveira

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA code to hide rows doesn't work across multiple tabs

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Registered User
    Join Date
    06-18-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: VBA code to hide rows doesn't work across multiple tabs

    Thanks AlphaFrog that worked a treat.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Macro for copying formulas to populated rows doesn't work for changes to multiple cells
    By Stuartzz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-06-2018, 06:43 PM
  2. On Error GoTo doesn't work when I use it multiple times in one code
    By stein7 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-28-2018, 10:11 PM
  3. Macro to hide rows on tabs in between (Begin:End) tabs only
    By alohadboy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-20-2017, 11:24 AM
  4. Testing single code, work fine. Put multiple codes in one sheet, one code doesn't work.
    By MayDay1988 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-30-2017, 06:14 PM
  5. Replies: 3
    Last Post: 02-24-2014, 02:39 PM
  6. Script doesn't work anymore (auto hide rows and columns
    By Crispy85 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-02-2013, 02:17 AM
  7. VBA code for (un)hide columns related to drop down list doesn't work
    By maumon in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-21-2010, 08:27 AM

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