+ Reply to Thread
Results 1 to 2 of 2

Macro button to expand/collapse: not work for newly added rows

  1. #1
    Registered User
    Join Date
    12-06-2018
    Location
    Vancouver, Canada
    MS-Off Ver
    2013
    Posts
    1

    Macro button to expand/collapse: not work for newly added rows

    After recorded the macro with the existing data, when I tried to add new rows and blank, it doesn't collapse those newly rows that blank. Do you know why? Macro code below:



    ================================================================
    Sub Button1()
    Application.ScreenUpdating = False
    ActiveSheet.Unprotect
    Selection.AutoFilter
    ActiveSheet.Range("$B$3:$H$146").AutoFilter Field:=2, Criteria1:="="
    ActiveSheet.Range("$B$3:$H$146").AutoFilter Field:=3, Criteria1:="="
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
    , AllowFormattingCells:=True, AllowFormattingColumns:=True, _
    AllowInsertingColumns:=True, AllowInsertingRows:=True, _
    AllowInsertingHyperlinks:=True, AllowDeletingColumns:=True, _
    AllowDeletingRows:=True, AllowSorting:=True, AllowFiltering:=True, _
    AllowUsingPivotTables:=True
    Application.ScreenUpdating = True
    End Sub

    Sub Button2()
    Application.ScreenUpdating = False
    ActiveSheet.Unprotect
    Selection.AutoFilter
    ActiveSheet.Range("$B$3:$H$146").AutoFilter Field:=3, Criteria1:="="
    ActiveSheet.Protect
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
    , AllowFormattingCells:=True, AllowFormattingColumns:=True, _
    AllowInsertingColumns:=True, AllowInsertingRows:=True, _
    AllowInsertingHyperlinks:=True, AllowDeletingColumns:=True, _
    AllowDeletingRows:=True, AllowSorting:=True, AllowFiltering:=True, _
    AllowUsingPivotTables:=True
    Application.ScreenUpdating = True
    End Sub

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Macro button to expand/collapse: not work for newly added rows

    Hi and welcome to the forum. Unfortunatel your post does not comply with Rule 2 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Please click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

+ 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. Macro to expand and collapse rows based on criteria in cells
    By jholiday78 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-26-2015, 10:32 AM
  2. Adding expand or collapse button without pivot or Grouping...
    By meus in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-27-2015, 02:07 AM
  3. VBA button that changes label when click ie. expand, collapse
    By jamesnos in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-27-2014, 08:32 PM
  4. Excel Macro to Collapse/Expand grouped rows and columns
    By magjayeck in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-28-2013, 10:58 AM
  5. Toggling Button Labels Between Expand/Collapse
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-27-2012, 08:09 AM
  6. [SOLVED] expand and collapse button with subtotals
    By TUNGANA KURMA RAJU in forum Excel General
    Replies: 1
    Last Post: 05-06-2006, 08:20 AM
  7. expand/collapse row button
    By caii in forum Excel General
    Replies: 3
    Last Post: 10-26-2005, 05:05 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