+ Reply to Thread
Results 1 to 4 of 4

Record macro hide cells breaks when rows or inserted or deleted

  1. #1
    Registered User
    Join Date
    12-23-2013
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2010
    Posts
    85

    Record macro hide cells breaks when rows or inserted or deleted

    Hey all,

    I recorded a simple macro and linked it to a button that hides rows 10-15 in a worksheet. There is another button that unhides the same rows. What do I need to add to the code to stop it from breaking when I insert or delete rows before 10-15?

    Do I have to name that range and then look up that named range? If so, how do I do that?

    I have attached an example for reference, and copied the code below.

    Cheers,
    B

    This is the code:

    Sub HideCells()
    '
    ' HideCells Macro
    '

    '
    Rows("10:15").Select
    Selection.EntireRow.Hidden = True
    End Sub
    Sub UnhideCells()
    '
    ' UnhideCells Macro
    '

    '
    Rows("9:16").Select
    Selection.EntireRow.Hidden = False
    Range("B9").Select
    End Sub
    Attached Files Attached Files

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,336

    Re: Record macro hide cells breaks when rows or inserted or deleted

    It would be something like
    Please Login or Register  to view this content.
    where RowsToHide is your Named Range and refers to cells in the rows to be hidden/unhidden.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    12-23-2013
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2010
    Posts
    85

    Re: Record macro hide cells breaks when rows or inserted or deleted

    Thought so, but nothing was coming up on my search. Sorry for the terrible question and thanks for the help!

    B

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,336

    Re: Record macro hide cells breaks when rows or inserted or deleted

    You're welcome. Thanks for the rep.



    The only "terrible question" is one you don't ask

+ 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 Hide blank rows and Unhide the rows with cells
    By Neilesh Kumar in forum Excel General
    Replies: 4
    Last Post: 04-12-2017, 06:06 AM
  2. Replies: 1
    Last Post: 12-17-2015, 03:35 AM
  3. [SOLVED] When record is created/deleted in Table1, then add/delete record to Table2
    By michellepace in forum Excel General
    Replies: 1
    Last Post: 11-26-2015, 04:45 AM
  4. [SOLVED] Attaching VBA code to an inserted Excel button to hide rows and change caption
    By TheScott in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-07-2014, 01:01 PM
  5. Replies: 0
    Last Post: 05-10-2013, 12:04 PM
  6. Keep Reference to a cell after Row or Column is inserted/deleted
    By BlueGunner in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-30-2010, 11:00 PM
  7. Page Breaks deleted
    By melsevier in forum Excel General
    Replies: 3
    Last Post: 03-22-2009, 06:38 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