+ Reply to Thread
Results 1 to 14 of 14

Loop thru two ranges

  1. #1
    Registered User
    Join Date
    01-19-2010
    Location
    Myslowice
    MS-Off Ver
    Excel 2003
    Posts
    6

    Loop thru two ranges

    Hi,

    I'm trying to speed up my work in excel. I need to fill some cells in first range to get + values in 2nd range. Loop seems to be best way for it, but i'm not to good in VBA. In attached file you can find 3rd worksheet. Loop must go thru all cells in range B25:AN32 and change related cells in range B15:AN22 until cell value in bottom range will be > 0.

    There is also 2nd problem I'd like to solve. In sheet KANBAN I've got simillar situation, but now i need to paste text into green range, to get values in bottom range until.

    Both loops must run from top to bottom, column by column.

    Thanks in advance for any help.
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Loop thru two ranges

    Can you elaborate? I don't understand.

    Loop must go thru all cells in range B25:AN32
    And do what?
    and change related cells in range B15:AN22
    How?
    until cell value in bottom range will be > 0
    What is the bottom range?

    An illustration usually helps in these cases.

  3. #3
    Registered User
    Join Date
    01-19-2010
    Location
    Myslowice
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Loop thru two ranges

    Hi,

    Bottom range is B25:AN32. Macro must fill top table. On attached file you can see direction of lookup. When loop will find first cell with negative value will change value in related cell from top range +1 until cell value in bottom range will be >0 and then will move to next cell. Hope this looks clear

    Thanks
    Attached Images Attached Images

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Loop thru two ranges

    Still not quite there. The cells in range B15:AN22 don't appear to have any connection with cells in the range B25:AN32. In fact, the latter reference the range B5:AN12. I should have made it clearer, but as an illustration, could you add the results you expect from the first few iterations?

  5. #5
    Forum Expert contaminated's Avatar
    Join Date
    05-07-2009
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Excel 2013
    Posts
    1,430

    Re: Loop thru two ranges

    I really want to help, but you must help us first. Please upload a workbook with desired outputs.
    Люди, питающие благие намерения, как раз и становятся чудовищами.

    Regards, ?Born in USSR?
    Vusal M Dadashev

    Baku, Azerbaijan

  6. #6
    Registered User
    Join Date
    01-19-2010
    Location
    Myslowice
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Loop thru two ranges

    Uploaded file with output and recorded macro how things should go. Once again thanks.
    Attached Files Attached Files

  7. #7
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Loop thru two ranges

    OK, my mistake, I didn't see before how the cells were connected. Try this:
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    01-19-2010
    Location
    Myslowice
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Loop thru two ranges

    Works great :), many thanks.
    Is there is any chance you could help me solve similar problem in sheet KANBAN ?
    This one is more complex (for me) because I need to paste proper text in proper sequence.

  9. #9
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Loop thru two ranges

    OK, again, can you clarify as I don't fully understand. Your file says
    CELLS MUST BE PASTED UNTIL MIN / MAX WILL BE REACHED, THEN MUST GO TO NEXT COLUMN ON THE RIGHT
    Which cells must be pasted and where must they go? Which cells must reach the min/max? As before, a small sample of expected results would help. Also, how, if at all, is this connected to the previous code?

  10. #10
    Registered User
    Join Date
    01-19-2010
    Location
    Myslowice
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Loop thru two ranges

    Hi,

    Sorry for not being precise. Output from previous sheet "'LAKIERNIA" in input for sheet KANBAN ( range1 B56:AL63) multiplied by 16. They are also input data for range2 B45:AN52. In range2 we have some negaitve values, which are connected with green marked fields (range D6:D37, F6:F37...). With the same way as it happend in sheet LAKIENIA they must be >0.
    This example will be little twisted, but it works like this.
    If you will paste "5D SAB" into cell D6, it will be catched in cell BI6 and will change its value into 1, then it will be multiplied by 16 in cell AC6. In result cell A56 will change by this16 and it will result, that cell J45 will increase its value. Next values 5D SAB must be pasted below cell D6 (D7:D12) until J45 > 0. Then loop is going row down. Macro "KANBAN' will ilustrate how it should work.
    For range D6:D37 cells must be filled until D38 = D40. I've quit MIN/MAX - just TARGET.
    Attached Files Attached Files

  11. #11
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Loop thru two ranges

    OK, that makes things a bit clearer, but still a couple of questions:

    - what exactly is the link between the ranges D6:D37, F6:F37 etc and the range B45:AN52? (These two sets are different sizes.) In other words, why does J45 being <0 mean you put "5D SAB" into D6? If B45 were <0 where would "5DSAB" go?

    - does meeting target have priority over the lower range being >=0? Or if one is met is the other automatically met? Your calculations are quite involved so I have not followed this through all the way.

  12. #12
    Registered User
    Join Date
    01-19-2010
    Location
    Myslowice
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Loop thru two ranges

    Let me explain what this is for. Range D6:D37 and F6:F37 represent welding sequence, left and right hand parts. Range B45: AN52 : each column represent truck - quantites that need to be welded in order to satisfy painting line (sheet LAKIERNIA) and painting line must satisfy trucks (parts for shipment in given quantites / sequence). I know what i should ship and what my stocks are ( sheet SUMMARY). Just need to find proper sequence and quantities for welding. In fist row, red cells shows truck 6 and top-bottom order of welding = 5D NSAB (cell G49). Each cell with value 3/5D N/SAB represent value of 16.

    Back to Q1
    When loop will find first cell with negative value (G49) should paste 5D NSAB into D6 in order to satisfy painting line with this item. By pasting this value into D6 cell BH6 will change its value into 1, then it will be multiplied by 16 (this is given batch for box on welding). Then it will be sum in cell AB39 and transfeted into cell AG43. Then it will be transfeted into sheet SUMMARY cell H20 and from all 3 shifts will be sum in K20. This sum will increase my overall quantities of item 5D NSAB LH and affect cell A60 in sheet KANBAN. This increase will also affect on range B45:AN52 cell B49,C49 .. G49 will be increased by this quantity and in result G49>=0. just to make clear cells A45:A52 represents values that should be pasted in given order (attached picture). According to sequence first 5D SAB will go into D16 (because it's LH). This was just example to picture links.

    Q2.

    If loop will meet target in 1st shift first column, should start filling cells in 2nd continuing sequence. In order words for LH columns: we are filling 31 cells in D6:D37, after target of filled cells was reached macro is moving into range K6:K37 and filling with 31 cells, then into range R6:R37 and after reaching target stop.
    Attached Images Attached Images

  13. #13
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Loop thru two ranges

    OK, will have a look later today or tomorrow.

  14. #14
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Loop thru two ranges

    Quite possibly I'm being dense, but I'm afraid I still cannot get my head completely round what is needed here.

    Perhaps either you can find another way to explain it, or somebody else will chip in. This problem is not dependent on the other code so it is a self-contained question as far as I can see.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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