+ Reply to Thread
Results 1 to 5 of 5

Amend VBA code to 'undo' previous run results before re-running code

  1. #1
    Registered User
    Join Date
    10-25-2016
    Location
    Birmingham, England
    MS-Off Ver
    2017
    Posts
    4

    Amend VBA code to 'undo' previous run results before re-running code

    The attached workbook is a 'template' for user to register their equipment details into sheet "AA_Data", In worksheet called "Sheet", is a template "Record Card" which, contains formulas to populate the headers from the data for each row completed in "AA_Data".

    Once the user has input their equipment details into "AA_Data", they click the COPY button, which runs below code.

    Please Login or Register  to view this content.

    This creates the specified number of duplicate copies of "Sheet" tab, and the formulas contained in this will populate the relevant info from the rows in "AA-Data"

    They then click on RENAME button, so "Sheet" and all its copies are renamed "Sheet1", "Sheet2", "Sheet3" etc, so they can then be printed off.

    Please Login or Register  to view this content.
    My issue is how to build into the code for when new rows of data are added to the "AA_Data" sheet. ( or if row is deleted). The COPY code wont re-run as the "Sheet" has been renamed "Sheet1", and so I need to add to code, where if "Sheet" does not exist, delete all sheets from "Sheet2" to last "Sheet??" (can be variable depending on how many rows of data are entered into "AA-Data" sheet) then rename "Sheet1" to "Sheet", so the Copy code can then re-run.

    I am new to VBA and am really not sure where to start on this one! Any advice appreciated.
    Attached Files Attached Files
    Last edited by sllewe55; 11-13-2017 at 06:31 PM.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525

    Re: Amend VBA code to 'undo' previous run results before re-running code

    Usually, you can loop through the sheets, and ignore the sheet you don't want to affect,

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    10-25-2016
    Location
    Birmingham, England
    MS-Off Ver
    2017
    Posts
    4

    Re: Amend VBA code to 'undo' previous run results before re-running code

    Hi, thanks for your response! I'll see if I can apply this to the code! However, may be beyond my current capabilities! Thanks.

  4. #4
    Registered User
    Join Date
    10-25-2016
    Location
    Birmingham, England
    MS-Off Ver
    2017
    Posts
    4

    Re: Amend VBA code to 'undo' previous run results before re-running code

    I have managed to work out the code to do what I want and it seems to work OK except for one issue with the Input Box, where the user enters the number of copies required, options available are 'OK' or 'Cancel', and if select 'Cancel' get "runtime error '13' Type mismatch" - would like to end code if user selects Cancel - is this possible?

    Please Login or Register  to view this content.
    I have merged codes I have found from searching online, so any suggestions to improve are much appreciated!

  5. #5
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525

    Re: Amend VBA code to 'undo' previous run results before re-running code

    Maybe this will work,
    Please Login or Register  to view this content.

+ 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] Amend code to check cell A2 has data in before running
    By robertguy in forum Excel General
    Replies: 2
    Last Post: 12-11-2016, 09:13 AM
  2. Results differ when running code with and without a BreakPoint
    By Barley_Biker in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-22-2015, 01:22 AM
  3. Help to amend code
    By ExcelFailure in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-15-2015, 08:28 AM
  4. how can i undo After running any other macro code
    By baig123 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-29-2014, 02:26 PM
  5. Re-code Userform to open range of sheets like previous sheet code
    By JJFletcher in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-15-2014, 02:31 AM
  6. [SOLVED] Excel VB code. Message pops up while code running asking question. Code must not wait.
    By Heinrich Venter in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-28-2014, 06:10 AM
  7. Getting Trendline formulae - results OK when stepping thru code, missing when running
    By thestormdragon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-18-2013, 08:15 PM

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