+ Reply to Thread
Results 1 to 5 of 5

For each loop only displaying last loop in all of my ranges

  1. #1
    Registered User
    Join Date
    12-11-2017
    Location
    Wales
    MS-Off Ver
    2007
    Posts
    3

    For each loop only displaying last loop in all of my ranges

    Hi everyone,
    I'm hoping someone can help me - I'm really new to VBA and trying to calculate an incentive pay out for each person as long as they have certain attendance and a certain score.
    But when I run my code it only shows the last persons incentive over all of the selected cells.
    I'm sure it's a simple fix but I just cannot work it out.
    Would really appreciate the help here is the code.

    Edited - I have attached an example spread sheet for you to look at with that the figures should output.

    Please Login or Register  to view this content.


    Thank you very much in advance.
    Last edited by mickeyb121; 12-13-2017 at 03:46 AM.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: For each loop only displaying last loop in all of my ranges

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Registered User
    Join Date
    12-11-2017
    Location
    Wales
    MS-Off Ver
    2007
    Posts
    3

    Re: For each loop only displaying last loop in all of my ranges

    Sorry about that, I've amended my post to hopefully comply. Thank you very much.

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,613

    Re: For each loop only displaying last loop in all of my ranges

    you have 3 nested loops, so in total you run set of commands between

    Please Login or Register  to view this content.
    and
    Please Login or Register  to view this content.
    11*11*11 = 1331 times, but output always go to (one of) 11 cells in range I8:I18

    in other words, for each of these 11 cells, you calculate 121 values , but overwrite previously calculated with new one, so at the end of the day your code is equivalent to 2 outmost loops on their last elements and thenm looping through I8:I18, like:

    Please Login or Register  to view this content.
    Hope this will help, but if it's not enough, would you please attach a SMALL sample Excel workbook(s) (10-20 rows of data is usually enough)? Please don't attach a picture of one (no-one will want to re-type all your stuff before starting).

    1. Make sure that your sample data are truly REPRESENTATIVE of your real data. (If trere are typical cases like: all unique values/duplicates could occur, day/night, nobody present/several persons at once, before/on/past due, etc. - please show them all or at least indicate in text) The use of unrepresentative data is very frustrating and can lead to long delays in reaching a solution.

    2. Make sure that your desired solution(s) is/are also shown (mock up the results manually).

    3. Make sure that all confidential/restricted information (either personal or business) like real e-mails, social security numbers, bank accounts, etc. is removed first!!

    To attach an Excel file you have to do the following: Just before posting, scroll down and press Go Advanced button and then scroll down and press Manage Attachments link. Now follow the instructions at the top of that pop-up screen.
    Best Regards,

    Kaper

  5. #5
    Registered User
    Join Date
    12-11-2017
    Location
    Wales
    MS-Off Ver
    2007
    Posts
    3

    Re: For each loop only displaying last loop in all of my ranges

    Hi, thank you so much for looking in to my code.
    When I remove the loops it just outputs 0.
    I want the loops to go through all the attendance list and their scorecard list on sheet 2 to calculate the incentive and output by the correct name on sheet1.

    Please excuse my spread sheet it's only there as an example as it's not the real one so doesn't look organised at all.
    I'll attach the spread sheet and hardcode how the output should be so you can see.

    Thank you very much,
    Attached Files Attached Files
    Last edited by mickeyb121; 12-12-2017 at 12:54 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] Loop macro displaying only certain cells and keeping their format
    By Antoine27182818 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-15-2014, 12:21 PM
  2. [SOLVED] Do While Loop Issue, in Displaying Data in Userform.
    By scottpattison in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-14-2013, 03:39 PM
  3. Using a For Loop with Ranges
    By an0593 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-30-2013, 02:28 AM
  4. [SOLVED] Copy dynamically changing column and Paste using VBA Loop (Loop within Loop)
    By nixon72 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-12-2013, 12:46 PM
  5. Loop thru two ranges
    By mindoff in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 01-22-2010, 07:46 AM
  6. using for-loop to name ranges
    By mashoutposse in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-06-2010, 08:09 AM
  7. [SOLVED] Displaying results of loop in cells
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-04-2005, 05:06 PM

Tags for this Thread

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