+ Reply to Thread
Results 1 to 4 of 4

Copy and Paste Macro with Named Ranges

  1. #1
    Registered User
    Join Date
    09-26-2018
    Location
    Dublin
    MS-Off Ver
    MS Office 2016
    Posts
    3

    Copy and Paste Macro with Named Ranges

    Very new to VBA so looking for some help shortening the below code - I know I should be using a loop but I can't figure out how to do so with the Scenario_Paste named ranges.

    Any pointers, greatly appreciated!


    Range("Scenario_No.").Value = 1
    Application.CalculateFull

    Range("Scenario_Copy").Copy
    Range("Scenario_Paste1").PasteSpecial xlPasteValuesAndNumberFormats

    Range("Scenario_No.").Value = 2
    Application.CalculateFull

    Range("Scenario_Copy").Copy
    Range("Scenario_Paste2").PasteSpecial xlPasteValuesAndNumberFormats


    Range("Scenario_No.").Value = 3
    Application.CalculateFull

    Range("Scenario_Copy").Copy
    Range("Scenario_Paste3").PasteSpecial xlPasteValuesAndNumberFormats


    Range("Scenario_No.").Value = 4
    Application.CalculateFull

    Range("Scenario_Copy").Copy
    Range("Scenario_Paste4").PasteSpecial xlPasteValuesAndNumberFormats



    Range("Scenario_No.").Value = 5
    Application.CalculateFull

    Range("Scenario_Copy").Copy
    Range("Scenario_Paste5").PasteSpecial xlPasteValuesAndNumberFormats



    Range("Scenario_No.").Value = 6
    Application.CalculateFull

    Range("Scenario_Copy").Copy
    Range("Scenario_Paste6").PasteSpecial xlPasteValuesAndNumberFormats



    Range("Scenario_No.").Value = 7
    Application.CalculateFull

    Range("Scenario_Copy").Copy
    Range("Scenario_Paste7").PasteSpecial xlPasteValuesAndNumberFormats



    Range("Scenario_No.").Value = 8
    Application.CalculateFull

    Range("Scenario_Copy").Copy
    Range("Scenario_Paste8").PasteSpecial xlPasteValuesAndNumberFormats


    Range("Scenario_No.").Value = 9
    Application.CalculateFull

    Range("Scenario_Copy").Copy
    Range("Scenario_Paste9").PasteSpecial xlPasteValuesAndNumberFormats


    Application.CutCopyMode = False


    End Sub

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Copy and Paste Macro with Named Ranges

    Here's one way to loop it. I could have also put the code in the subroutine CopyScenario inside the loop rather than call it from the loop.

    Please Login or Register  to view this content.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Registered User
    Join Date
    09-26-2018
    Location
    Dublin
    MS-Off Ver
    MS Office 2016
    Posts
    3

    Re: Copy and Paste Macro with Named Ranges

    Great thank you for your help! Really appreciate it.

    One element doesn't seem to be running correctly. After each scenario is run, I want the results to be pasted only in that applicable scenario and not in all scenario ranges - currently, the results from scenario 9 (last scenario) are being pasted into all the paste ranges. Do you know a quick fix for that?

  4. #4
    Registered User
    Join Date
    09-26-2018
    Location
    Dublin
    MS-Off Ver
    MS Office 2016
    Posts
    3

    Re: Copy and Paste Macro with Named Ranges

    Quote Originally Posted by GavinF View Post
    Great thank you for your help! Really appreciate it.

    One element doesn't seem to be running correctly. After each scenario is run, I want the results to be pasted only in that applicable scenario and not in all scenario ranges - currently, the results from scenario 9 (last scenario) are being pasted into all the paste ranges. Do you know a quick fix for that?

    Nevermind, it does run correctly. I ran the wrong sub - thanks again, it's very helpful

+ 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. Copy values of all named range in wb1 to identically named ranges in wb2
    By JAMIAM in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-24-2016, 06:58 PM
  2. Copy/Paste Named Ranges but nothing happens, with no runtime error
    By dietcoke802 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-06-2013, 11:54 AM
  3. [SOLVED] Copy and Paste Macro~ issue with named workbook
    By Markarmi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-24-2013, 09:04 AM
  4. Replies: 2
    Last Post: 01-03-2013, 01:29 AM
  5. [SOLVED] Macro to copy and paste Ranges
    By djmarsh51 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-14-2012, 01:58 PM
  6. Copy & paste from cells below named ranges
    By Glio in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-19-2007, 08:15 AM
  7. Copy and paste two named ranges together.
    By ACDenver in forum Excel General
    Replies: 3
    Last Post: 10-20-2005, 07:05 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