+ Reply to Thread
Results 1 to 12 of 12

repeating a macro in every row (for multiple cells)

  1. #1
    Registered User
    Join Date
    07-09-2008
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    91

    repeating a macro in every row (for multiple cells)

    hi!

    I have been looking around the forum and found this thread to the the closest what I am trying to achieve: http://www.excelforum.com/excel-prog...every-row.html

    Basically I have two worksheets, one labeled "data" and the other labeled "calc".

    For each row of "data" starting from row 2, I need to copy 5 values (columns AA, L, I, M, P) into the "calc" worksheet (cells D11, D12, H11, H12, H13) respectively.

    Then the "calc" sheet automatically does the calculations and we get the result in R10 of the "calc" sheet.

    Lastly this resulting value R10 needs to be copied back to the "data" sheet in column AB of each row.

    I have recorded the macro doing this for the row 2 as per below:

    Please Login or Register  to view this content.
    I have tried modifying the code to make it repeat, but no luck...

    Is there an easy way to adapt what was posted in http://www.excelforum.com/excel-prog...every-row.html to suit what I am trying to do?

    Thank you so much in advanced for your help!
    Last edited by hluk; 03-28-2012 at 05:37 PM.

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: repeating a macro in every row (for multiple cells)

    Hi

    Try this
    Please Login or Register  to view this content.
    rylo

  3. #3
    Registered User
    Join Date
    07-09-2008
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    91

    Re: repeating a macro in every row (for multiple cells)

    hi rylo, thanks for the help!

    I tried running the macro and nothing is being recorded in the column AB of "data".

    I think the macro is working though otherwise?

  4. #4
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: repeating a macro in every row (for multiple cells)

    Hi

    Sorry the line

    Please Login or Register  to view this content.
    should be

    Please Login or Register  to view this content.
    rylo

  5. #5
    Registered User
    Join Date
    07-09-2008
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    91

    Re: repeating a macro in every row (for multiple cells)

    oh thanks rylo!!!

    last thing. is there a simple line we can add to check in each row if "AB" has a value already or not?

    if there is a value, skip to next line

    if there is no value, perform the macro

    - i love these forums!

  6. #6
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: repeating a macro in every row (for multiple cells)

    Hi

    Please Login or Register  to view this content.
    rylo

  7. #7
    Registered User
    Join Date
    07-09-2008
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    91

    Re: repeating a macro in every row (for multiple cells)

    thanks again for the reply!

    is there anyway to prevent it from looping through altogether if there is a value?

    the reason I ask is... when i have a lot of data, running the macro through the sheet could take a long time if each row is looped through.

    thus, if there is already a value, we can skip the row to save on computing time/load.

    thanks for you help thus far. don't worry about this if this is getting too complicated...

    THANKS!

  8. #8
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: repeating a macro in every row (for multiple cells)

    Hi

    Sure, just put the test on the length of R10 as the first action of the loop. If it is >0, then do the actions, otherwise move on.

    rylo

  9. #9
    Registered User
    Join Date
    07-09-2008
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    91

    Re: repeating a macro in every row (for multiple cells)

    thanks rylo!

    i had to change it from "If it is >0, then do the actions, otherwise move on"

    to "If it is =0, then do the actions, otherwise move on."

    same concept thought

    here is the final code that is working for me for anyone else interested:

    Please Login or Register  to view this content.
    you see anything wrong with this rylo? thanks!

  10. #10
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: repeating a macro in every row (for multiple cells)

    Hi

    D'oh. Yea got the test back to front. Looks OK.

    rylo

  11. #11
    Registered User
    Join Date
    07-09-2008
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    91

    Re: repeating a macro in every row (for multiple cells)

    thanks buddy! marked as solved.

    anything i can do to UP your rep?

  12. #12
    Registered User
    Join Date
    07-09-2008
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    91

    Re: repeating a macro in every row (for multiple cells)

    figured out how to +1 rep

    just did it!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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