+ Reply to Thread
Results 1 to 12 of 12

Run a single row macro on multiple rows

  1. #1
    Registered User
    Join Date
    10-15-2014
    Location
    RI
    MS-Off Ver
    2010
    Posts
    6

    Run a single row macro on multiple rows

    Hi,
    I have a spreadsheet with multiple of rows containing cells with formulas. The formulas provide suggested results but we let users manually override certain cells in a row. We want to be able to let a user make changes on any rows, but if they choose they can revert the entire row back to it's original state (containing all formulas and no overrides). To do this I created a macro which copies the formulas from a control row (that nobody touches) and pastes them into a row I chose when recording the macro. How can I get it so a user can select any rows they want and run the macro to get the original formulas back?

    I appreciate any input.
    Here is the code from the macro:

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Run a single row macro on multiple rows

    This will allow a user to select a range then hit OK.


    Please Login or Register  to view this content.
    Last edited by mikeTRON; 10-15-2014 at 05:40 PM.
    Please ensure you mark your thread as Solved once it is. Click here to see how.
    If a post helps, please don't forget to add to our reputation by clicking the star icon in the bottom left-hand corner of a post.

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Run a single row macro on multiple rows

    Like so to update the current row with the original formulas:
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Registered User
    Join Date
    10-15-2014
    Location
    RI
    MS-Off Ver
    2010
    Posts
    6

    Re: Run a single row macro on multiple rows

    mikeTRON,
    Thank you for the quick reply. Do I paste this code withing the current macro code? Is so, could you please advise where? Unfortunately, I am not very experienced in what the code means.

    Thanks

  5. #5
    Registered User
    Join Date
    10-15-2014
    Location
    RI
    MS-Off Ver
    2010
    Posts
    6

    Re: Run a single row macro on multiple rows

    JBeaucaire,
    This does exactly what I was looking for. Thank you. Is there a way with a slight tweak to the code that the user could select multiple rows before running the macro?
    Thanks again

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Run a single row macro on multiple rows

    The user needs to select rows by selecting in column A... then this would work:

    Please Login or Register  to view this content.
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

  7. #7
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Run a single row macro on multiple rows

    Nice. Is there any reason you are copying and pasting instead of just spomething like this:
    Please Login or Register  to view this content.

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Run a single row macro on multiple rows

    I didn't test, but I feared that would do strange things with relative/absolute referencing thing. I should probably test, that's a way more elegant solution if it works correctly.

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Run a single row macro on multiple rows

    yeah, I just tested it, that technique makes an identical copy of the original formula in the new cell, it doesn't update the relative references the way copy/paste does. Too bad.

  10. #10
    Registered User
    Join Date
    10-15-2014
    Location
    RI
    MS-Off Ver
    2010
    Posts
    6

    Re: Run a single row macro on multiple rows

    JBeaucaire,
    The help you offered works great however one more caveat... Is there a way to make this macro work if users select multiple rows at once? Right now even with multiple rows selected, the macro only runs against the first row of the selection. Ideally it would run against all selected rows.
    Here is what the current code looks like.
    Thanks

    Please Login or Register  to view this content.

  11. #11
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Run a single row macro on multiple rows

    Maybe this:
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    10-15-2014
    Location
    RI
    MS-Off Ver
    2010
    Posts
    6

    Re: Run a single row macro on multiple rows

    Thanks JBeaucaire,
    Appears to be working as expected. Great job!
    Last edited by tomnewengland; 12-08-2014 at 02:27 PM.

+ 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 to transpose multiple rows to a single column
    By Gup in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 10-12-2014, 03:05 PM
  2. [SOLVED] Transpose Multiple Rows into a Single Row and Randomize in the Same Macro
    By bwalks in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 09-07-2014, 08:37 PM
  3. Replies: 5
    Last Post: 05-25-2013, 07:12 AM
  4. Multiple Rows to Single Rows, Macro?
    By jetta1 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-06-2013, 05:33 PM
  5. [SOLVED] Need Macro to move multiple rows into a single row for each 'Record ID'
    By jonathanseah.87 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-05-2012, 10:21 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