+ Reply to Thread
Results 1 to 9 of 9

do until loop need help with this problem

  1. #1
    Forum Contributor
    Join Date
    06-18-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    102

    do until loop need help with this problem

    I am trying to make a macro for the following problem:


    A1-Amount to Subtract to Zero
    A2-45.20
    A3-20.30
    A4-10.00
    A5-2.00

    B1-Amounts to be subtracted from
    B2-75.20
    B3-5.50
    B4-16.00
    B5-13.20

    C1-Amount Left
    C2-0
    C3-5.50
    C4-13.70
    C5-13.20



    Alright this is my table and the heading say what each column should be. I want to take each amount in column A and subtract them from the max value in column b until every amount in column A reach 0. I don't want any negative numbers when a number reaches 0 in column B and I still have an amount left from column A I want to just carry that value and subtract it from the next highest value in B. I want each value in Column A to reach 0 when I am done.

    Manually this is how i would do this problem

    I would subtract 45.20 from 75.20 and then A1=0 and B1=30.00.

    I would move on to A2 and subtract 20.30 from B1 which had 30.00 dollars left. A2=0 and B1=9.70.

    I would move on to A3 and subtract 9.70 of A3 from B1 9.70 making B1 zero then subtract the remaining 30 cents to from B3=16.00 making B3=15.70.

    I choose B3 instead of B2 because I want to take the largest values so the process is shorter.

    A3 would equal 0 so I would move on to A4 and subtract 2.00 from B3=15.70 leaving B3 13.70

    Column C would show the amounts remaining for column B to make sure we can tell how much is left after subtracting from the original amount.

    I hope this makes sense. I've been trying different processes but I just can't grasp how to loop through both ranges.
    Attached Files Attached Files
    Last edited by carden2; 07-03-2012 at 03:17 PM.

  2. #2
    Forum Contributor
    Join Date
    10-08-2010
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    386

    Re: do until loop need help with this problem

    try this

    Please Login or Register  to view this content.
    Last edited by GaidenFocus; 06-29-2012 at 04:46 PM.

  3. #3
    Forum Contributor
    Join Date
    06-18-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    102

    Re: do until loop need help with this problem

    I'll try this first thing monday morning and post a reply.

    Thank you very much.

  4. #4
    Forum Contributor
    Join Date
    06-18-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    102

    Re: do until loop need help with this problem

    I get an error on
    If ActiveCell.Value > LocHighB.Value And LocHighB.Value <> 0 Then

  5. #5
    Forum Contributor
    Join Date
    06-18-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    102

    Re: do until loop need help with this problem

    anyone have any ideas?

  6. #6
    Forum Contributor
    Join Date
    06-18-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    102

    Re: do until loop need help with this problem

    bump still trying to figure this out

  7. #7
    Forum Contributor
    Join Date
    10-08-2010
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    386

    Re: do until loop need help with this problem

    It worked fine for me. Here ill post the workbook.
    Attached Files Attached Files
    Last edited by GaidenFocus; 07-02-2012 at 04:12 PM.

  8. #8
    Forum Contributor
    Join Date
    06-18-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    102

    Re: do until loop need help with this problem

    Quote Originally Posted by GaidenFocus View Post
    It worked fine for me. Here ill post the workbook.
    thank you. I got it to work as well.

  9. #9
    Forum Contributor
    Join Date
    10-08-2010
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    386

    Re: do until loop need help with this problem

    Make sure you use the new one, the old one will lock up if the a column has value and the b column does not!

+ 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