+ Reply to Thread
Results 1 to 2 of 2

How to auto update the macro cell reference when new rows are added or deleted.

  1. #1
    Registered User
    Join Date
    01-17-2013
    Location
    United States
    MS-Off Ver
    Excel 2012
    Posts
    5

    How to auto update the macro cell reference when new rows are added or deleted.

    When I Insert A Row My Excel Macro Don't work

    Hi,

    I'm very green to using macros. I have created 2 simple macro buttons, one to clear contents “” in specific cells in a column
    Sub CLEAR_Click()
    Range("C15").Value = ""
    Range("C17").Value = ""
    Etc.
    Range("C374").Value = ""
    MsgBox "Pricelist Cleared"
    End Sub
    and another macro button to populate those same cells with the “1”.
    Sub RESET_Click()
    Range("C15").Value = "1"
    Range("C17").Value = "1"
    Etc.
    Range("C374").Value = "1"
    MsgBox "Pricelist Reset"
    End Sub

    There are hundreds of rows and some rows are skipped this is why I had to reference each cell individually instead of a range. I always need to add rows to the spreadsheet, this means I am constantly updating the Cell References the Macro refers to.

    Since I am so green I haven’t a clue how to begin. I’ve seen the:
    LastRow = Cells(Rows.Count, "A").End(xlUp).Row

    But I’m unsure how/where to add it and inserting this doesn’t help.

    I’ve seen other elaborate methods like Dynamic Name Ranges or Range("MyName") but without any hard examples or any intelligible ‘how to’ examples.

    It is also not feasible to add content in another column.

    It’s a nightmare because every time a new product is added all the macro's need updating. I know that the formulas update automatically when rows or columns are added. Why can't macros!?

    Can anyone please include the correct LastRow or Name Range etc? I just seem to have enough knowledge to be dangerous.

    Many Thanks.

    Trenton

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,640

    Re: How to auto update the macro cell reference when new rows are added or deleted.

    Hi there,

    As usual, there is more than one way to approach this requirement and the most suitable way will depend on your workbook/worksheet layout.

    Can you post a sample of your workbook here? We don't need to see meaningful data, just how the workbook and worksheets are laid out. Also, can you give us an idea of where new data (product?) rows are added - are they all in a single block or are there empty rows between data rows?

    Regards,

    Greg M

+ 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] code to auto number rows - that will update when rows are added/deleted
    By dkitzerow in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-12-2015, 10:45 AM
  2. update target sheet with rows as they are added or deleted to master sheet
    By RLR31064 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-20-2014, 05:41 PM
  3. [SOLVED] filter option always available on tables when rows are added and deleted through macro
    By emilyloz in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 07-08-2013, 09:25 AM
  4. Auto add date when data added/modified/deleted in cell.
    By serahkins in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-25-2012, 08:11 AM
  5. Replies: 1
    Last Post: 01-09-2011, 11:08 PM
  6. Sum values in cell from variable rows (rows are added and deleted)
    By drewship in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-06-2010, 08:38 AM
  7. [SOLVED] Linking a cell to update when rows added
    By kunjals@gmail.com in forum Excel General
    Replies: 0
    Last Post: 07-20-2005, 10: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