+ Reply to Thread
Results 1 to 31 of 31

Macro to loop through rows, if criteria is met then certain action is performed

  1. #1
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Macro to loop through rows, if criteria is met then certain action is performed

    Hi guys. I need to have a quite clever macro to loop through some rows and if certain criteria is met then perform certain actions.

    Information on the spreadsheet is a on going and ever growing (row wise) master list so over period of time more and more lines will be added to it.Currently its more than 2000 lines. About 30 to 150 lines is added each day or so. Horizontally information range on the spreadsheet is from Col A to Col J. Cells in columns C and G are used to determine if criteria is met. If criteria is met then cells in column G and I will be manipulated. I will try to give plenty of examples to try to explain what I need to achieve.

    Criteria.
    First objective is to is to figure out if "No" duplicate line, "Semi" duplicate line or "Full" duplicate line exists.
    So macro should loop through columns C and column G to determine if one of these three might exist. I imagine the loop trough happens in from bottom to top.

    No duplicate line - cell in column C is unique (it does not equals to any other cell in column C). Looking cell in column G is not required.
    Example:

    -------col C ------------------------------------col G----------------------------------------------Col I
    181026716910------------RN-207368----------------------------------------------------------1
    181026688710------------RN-207386----------------------------------------------------------1
    181026688810------------RN-207414, RN-207415, RN-207416------------------------5
    181026691110------------RN-207394----------------------------------------------------------1
    181026691210------------RN-207392----------------------------------------------------------1
    181026691310------------RN-207400, RN-207401, RN-207402------------------------7
    181026689510------------RN-207397----------------------------------------------------------1
    181026689610------------RN-207399----------------------------------------------------------1
    181026716910------------RN-207368, RN-207369, RN-207370------------------------2
    181026688710------------RN-207399----------------------------------------------------------1
    181026688810------------RN-207414----------------------------------------------------------1

    none of the cells in col C is duplicate.




    Semi duplicate line - cell in column C is duplicate (it equals to some other cell in column C. Now we are comparing cell value in column G (lowest row of the duplicate against the values of the upper duplicates. If the upper duplicates do not contain the value of lowest duplicate cell we then have a semi duplicate .
    Example1:

    -------col C ------------------------------------col G----------------------------------------------Col I
    181026716910------------RN-207368----------------------------------------------------------1
    181026688710------------RN-207386----------------------------------------------------------1
    181026691210------------RN-207414, RN-207416-----------------------------------------4
    181026691110------------RN-207394----------------------------------------------------------1
    181026691210------------RN-207392----------------------------------------------------------1
    181026691310------------RN-207400, RN-207401, RN-207402------------------------1

    Edit: notice the red ones in column C are duplicates. In column G there are no duplicates

    Or
    Example2:

    -------col C ------------------------------------col G----------------------------------------------Col I
    181026716910------------RN-207380----------------------------------------------------------1
    181026688710------------RN-207090----------------------------------------------------------1
    181026688810------------RN-207343----------------------------------------------------------1
    181026699410------------RN-207209----------------------------------------------------------1
    181026699410------------RN-207210----------------------------------------------------------1
    181026699410------------RN-207211----------------------------------------------------------1
    181026713110------------RN-207418----------------------------------------------------------1
    181026712910------------RN-207412----------------------------------------------------------1

    Edit: notice the red ones in column C are duplicates. In column G there are no duplicates



    Full duplicate line - cell in column C is duplicate (it equals to some other cell in column C . Now we are comparing cell value in column G (lowest row of the duplicate) against the values of the upper duplicates. If the upper duplicates contain the value of lowest duplicate we then have a Full duplicate .
    Example1:

    -------col C ------------------------------------col G----------------------------------------------Col I
    181026716910------------RN-207368----------------------------------------------------------1
    181026688710------------RN-207386----------------------------------------------------------1
    181026691210------------RN-207414, RN-207415, RN-207416------------------------4
    181026691110------------RN-207394----------------------------------------------------------1
    181026691210------------RN-207415----------------------------------------------------------2
    181026691310------------RN-207400, RN-207401, RN-207402------------------------1

    Edit: notice the red ones in column C and G are duplicates.

    Or
    Example2:
    -------col C ------------------------------------col G----------------------------------------------Col I
    181026716910------------RN-207380----------------------------------------------------------1
    181026688710------------RN-207090----------------------------------------------------------1
    181026688810------------RN-207343----------------------------------------------------------1
    181026699410------------RN-207216----------------------------------------------------------1
    181026699410------------RN-207216----------------------------------------------------------1
    181026699410------------RN-207216----------------------------------------------------------1
    181026713110------------RN-207418----------------------------------------------------------1
    181026712910------------RN-207412----------------------------------------------------------1

    Edit: notice the red ones in column C and G are duplicates.


    Action taken if criteria is met
    Action taken if criteria is met

    Depending of the outcome of criteria check:
    1) there is no action taken
    2) certain rows are combined together and then others will be deleted.
    3) certain rows are deleted


    No duplicate line - in this scenario no action is taken
    All the rows will be left as they were


    Semi duplicate line- there are some actions to be taken with cells in column G and Column I. Column G contains certification numbers. 90 percent of the time they start with letters RN. Column I contains quantities ie numbers. So now we need to combine all the information of column G and I. It should be done on the lowest row of these duplicates. So all the certification numbers should be combined together in this following style if possible: RN-xxxx, RN-xxxx, RN-xxxx, RN-xxxx,. So comma and space would be used. Other styles could be used as well if comma and space is not be possible. Now with column I the numbers should just be summed up. All these should be done in that last row of respective semi duplicate. Alternatively a new row can be created to the to the end of the list (first available empty row) and get the information there. But then all the information in other columns should be carried along as well. Now all the duplicate rows except that last one should be deleted.

    Continues with POST 2
    Last edited by rain4u; 04-14-2011 at 03:46 PM. Reason: Tried to make it bit cleared. Long post created early hours oh midnight.

  2. #2
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: Macro to loop through rows, if criteria is met then certain action is performed

    Example1
    The following should change:
    -------col C ------------------------------------col G----------------------------------------------Col I
    181026716910------------RN-207368----------------------------------------------------------1
    181026688710------------RN-207386----------------------------------------------------------1
    181026691210------------RN-207414, RN-207416-----------------------------------------4
    181026691110------------RN-207394----------------------------------------------------------1
    181026691210------------RN-207392----------------------------------------------------------1
    181026691310------------RN-207400, RN-207401, RN-207402------------------------1


    to this:

    -------col C ------------------------------------col G----------------------------------------------Col I
    181026716910------------RN-207368----------------------------------------------------------1
    181026688710------------RN-207386----------------------------------------------------------1
    181026691110------------RN-207394----------------------------------------------------------1
    181026691210------------RN-207414, RN-207416, RN-207392------------------------5
    181026691310------------RN-207400, RN-207401, RN-207402------------------------1


    Example2:
    The following should change:

    -------col C ------------------------------------col G----------------------------------------------Col I
    181026716910------------RN-207380----------------------------------------------------------1
    181026688710------------RN-207090----------------------------------------------------------1
    181026688810------------RN-207343----------------------------------------------------------1
    181026699410------------RN-207209----------------------------------------------------------1
    181026699410------------RN-207210----------------------------------------------------------1
    181026699410------------RN-207211----------------------------------------------------------1
    181026713110------------RN-207418----------------------------------------------------------1
    181026712910------------RN-207412----------------------------------------------------------1


    to this:

    -------col C ------------------------------------col G----------------------------------------------Col I
    181026716910------------RN-207380----------------------------------------------------------1
    181026688710------------RN-207090----------------------------------------------------------1
    181026688810------------RN-207343----------------------------------------------------------1
    181026699410------------RN-207209, RN-207210, RN-207211------------------------3
    181026713110------------RN-207418----------------------------------------------------------1
    181026712910------------RN-207412----------------------------------------------------------1


    Full duplicate line- all the duplicate lines should be deleted, except the top one.

    Example1:
    The following should change:
    -------col C ------------------------------------col G----------------------------------------------Col I
    181026716910------------RN-207368----------------------------------------------------------1
    181026688710------------RN-207386----------------------------------------------------------1
    181026691210------------RN-207414, RN-207415, RN-207416------------------------4
    181026691110------------RN-207394----------------------------------------------------------1
    181026691210------------RN-207415----------------------------------------------------------2
    181026691310------------RN-207400, RN-207401, RN-207402------------------------1


    To this:
    -------col C ------------------------------------col G----------------------------------------------Col I
    181026716910------------RN-207368----------------------------------------------------------1
    181026688710------------RN-207386----------------------------------------------------------1
    181026691210------------RN-207414, RN-207415, RN-207416------------------------4
    181026691110------------RN-207394----------------------------------------------------------1
    181026691310------------RN-207400, RN-207401, RN-207402------------------------1

    Or
    Example2:
    The following should change:

    -------col C ------------------------------------col G----------------------------------------------Col I
    181026716910------------RN-207380----------------------------------------------------------1
    181026688710------------RN-207090----------------------------------------------------------1
    181026688810------------RN-207343----------------------------------------------------------1
    181026699410------------RN-207216----------------------------------------------------------1
    181026699410------------RN-207216----------------------------------------------------------1
    181026699410------------RN-207216----------------------------------------------------------1
    181026713110------------RN-207418----------------------------------------------------------1
    181026712910------------RN-207412----------------------------------------------------------1

    to this:

    -------col C ------------------------------------col G----------------------------------------------Col I
    181026716910------------RN-207380----------------------------------------------------------1
    181026688710------------RN-207090----------------------------------------------------------1
    181026688810------------RN-207343----------------------------------------------------------1
    181026699410------------RN-207216----------------------------------------------------------1
    181026713110------------RN-207418----------------------------------------------------------1
    181026712910------------RN-207412----------------------------------------------------------1

    I hope this sort of macro is possible. For the time being I'm doing all this manually. First I copy over some new information to this master list. Then with a help of conditional formating I have all duplicates in column C highlighted in red. From there its using filters, copy, paste typing. deleting rows etc. I hope someone knows how to achieve this with macro. Feel free to use any method. You can also use helper cells from column K onwards etc. I will attach spreadsheet that has the real data (shortened version of it) with example before and after sheets. If you run your test macro on sheet "before" and then alternate couple times between sheets "before" and "after", then everything highlighted in purple should look more or less the same. I have created sheet "after" manually of course. On those sheets consider anything above the green line as a master list and anything below it as newly added information.


    Any help is very appreciated.



    Cheers
    Rain
    Attached Files Attached Files
    Last edited by rain4u; 04-08-2011 at 07:08 PM.

  3. #3
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: Macro to loop through rows, if criteria is met then certain action is performed

    *Bump*
    I'm not sure this macro can be achieved. Can anyone advise me if you think that it is even possible to do this kind of macro? I know I made awfully long post but I thought to provide more information rather to keep it skinny.

  4. #4
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: Macro to loop through rows, if criteria is met then certain action is performed

    *bump* *bump*

  5. #5
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Macro to loop through rows, if criteria is met then certain action is performed

    hi, rain4u, hope it helps, it works as you wish on your example but I do not know if it will on a real data. Please check attachment, run code "test".

    PS. I left your comments in the right most column to ease checking the result. If you do not need them anymore, please change 11 to 9 here:

    Please Login or Register  to view this content.
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: Macro to loop through rows, if criteria is met then certain action is performed

    What can I say. There is no limit for your talent. You are absolutely bloody amazing. It is almost note perfect. The only thing if can ask is would it be possible to have the result on the same sheet where original is i.e. it wouldn't create new sheet? Can this be done?

    There is a small bug but you didn't have chance to be aware of it as the circumstances were not on the example sheet. If there are duplicate lines and by this I mean 100% duplicate line (cell in column C and G together match entirely with some other lines either below or above) then they might cause problems. Let me illustrate.
    Normally the following should change:
    -------col C ------------------------------------col G----------------------------------------------Col I
    181026716910------------RN-207368----------------------------------------------------------1
    181026688710------------RN-207386----------------------------------------------------------1
    181026691210------------RN-207414, RN-207416-----------------------------------------4
    181026691110------------RN-207394----------------------------------------------------------1
    181026691210------------RN-207392----------------------------------------------------------1



    to this:

    -------col C ------------------------------------col G----------------------------------------------Col I
    181026716910------------RN-207368----------------------------------------------------------1
    181026688710------------RN-207386----------------------------------------------------------1
    181026691110------------RN-207394----------------------------------------------------------1
    181026691210------------RN-207414, RN-207416, RN-207392------------------------5





    But lets say there is a 100% duplicates further below like this

    -------col C ------------------------------------col G----------------------------------------------Col I
    181026716910------------RN-207368----------------------------------------------------------1
    181026688710------------RN-207386----------------------------------------------------------1
    181026691210------------RN-207414, RN-207416-----------------------------------------4
    181026691110------------RN-207394----------------------------------------------------------1
    181026691210------------RN-207392----------------------------------------------------------1
    181026691210------------RN-207392----------------------------------------------------------1
    181026691210------------RN-207392----------------------------------------------------------1


    then the current macro would turn it into this:
    -------col C ------------------------------------col G----------------------------------------------Col I
    181026716910------------RN-207368----------------------------------------------------------1
    181026688710------------RN-207386----------------------------------------------------------1
    181026691110------------RN-207394----------------------------------------------------------1
    181026691210------------RN-207414, RN-207416, RN-207392------------------------5
    181026691210------------RN-207392----------------------------------------------------------1
    181026691210------------RN-207392----------------------------------------------------------1

    It also messes up some other stuff as well if this kind of situation exists but I couldn't even figure out what was happening. Simplest way to overcome of this problem would be to have few lines of code before your awesome code that would remove any lines where cells in column C and G are 100% match withs some other cells in other rows. I updated the test xls to present this problem. I just copied the last line and made 5 rows of duplications. Can you see if you can fix this. i would be very thankful.


    PS!
    I tried the code on the real file and it was lightning fast. If it would keep the result on the same sheet that would be amazing. If not I can probably work around it.
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Macro to loop through rows, if criteria is met then certain action is performed

    hi, rain4u, I've corrected the code in order to get correct processing of 100% dupes. Please check attachment.
    I have not deleted creating new sheet as I do not know where to put the result on the main sheet.
    It looks pretty good to me. Hope you'd love it too. Please advise where the result should be placed.
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: Macro to loop through rows, if criteria is met then certain action is performed

    Thank you for the update.
    There is a small bug with it. After running the macro the results should look exactly the same as on "after" sheet. If you look column K where I have numbered the comments, number 1 and 4 are missing. With your previous iteration that was the not the case, so it must be to do with the new conditions I presented. I have tried to understand there whether there is a some sort of conflict of where I have asked two different actions in same situation and I cant figure this out. I have spent the last 45 minute doing and it still puzzles me. Can you have a look and see If you spot something where its possibly conflicting?

    Regards where to put the results. I kind of now like the idea getting having the results on a separate sheet. But can we do it this way that it would be a permanent sheet called "results". This actually gives me a chance to easily flick over the sheets and compare the out come. Very handy in testing period. But the original idea was to have everything replaced on the origin sheet with the outcome. But I can later easily do this in the following way: your macro takes the information from sheet A, works its magic on it and produces an outcome on sheet B. I can then edit the code to clear contents of sheet A and copy contents of sheet B back to sheet A.

    Cheers
    Rain
    Last edited by rain4u; 04-12-2011 at 02:22 PM.

  9. #9
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Macro to loop through rows, if criteria is met then certain action is performed

    please check attachment
    Attached Files Attached Files

  10. #10
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: Macro to loop through rows, if criteria is met then certain action is performed

    Code looks to be working perfectly.
    I will know for a fact if there are any bugs with it within a in a weeks time but I think it gets it spot on right. I have every confidence in the code as the test I did at work looked right.I would like to removed column E and H as that unnecessary info that we never seem to use. Just to give it a lot more tidier look. I tried to change the numbers 7 to 6 and 9 to 8 as i figured those are the columns that the code is looking.. But doing only that does give the right result but looses the header information. I noticed that there is also column 2 somehow used. Can you help me one more time with this sheet to adjust it to the alteration. Also I created a permanent sheet within the workbook called results. Is it possible to amend the code so it will always place results there. I tried to amend it myself and quite don't get it right

    I very pleased with the code as it will make my life and two of my colleagues life easier. As they are more older people they will definitely be happy with it as they don't feel very confident with computers.


    Thank you for the all the help so far. If you don't mind I would like to ask also help with one other code that you have previously done that relates to this one. Is that OK?

    Cheers
    Rain
    Attached Files Attached Files

  11. #11
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Macro to loop through rows, if criteria is met then certain action is performed

    can you provide file with original data and result you need to obtain

  12. #12
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: Macro to loop through rows, if criteria is met then certain action is performed

    Edit. oops. Double posting.
    Last edited by rain4u; 04-13-2011 at 07:09 PM.

  13. #13
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: Macro to loop through rows, if criteria is met then certain action is performed

    Hi watersev
    I redid the instructions. But fundamentally the only thing that has changed from your post #9 attachment is that 2 columns namely E and H have been removed/deleted. This is from the starting setup. Because these columns have been removed from the start up setup, your code is now just looking to wrong places. All you need to to do is re-align the code so its looking the right columns. Regardless I re-did new instructions. I hope you will understand them as I'm not very good creating very clear instructions. Please note there are 4 sheets within this workbook and each one of them includes comments.


    I'm very thankful of your support. I hope one day I can help some other people myself. There is so much to learn but I'm sure I will get there eventually.


    Cheers

    Rain
    Attached Files Attached Files
    Last edited by rain4u; 04-13-2011 at 07:15 PM.

  14. #14
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Macro to loop through rows, if criteria is met then certain action is performed

    please check attachment
    Attached Files Attached Files

  15. #15
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: Macro to loop through rows, if criteria is met then certain action is performed

    This is what I wanted. I will close this thread now.

    I normally don't find myself in this sort of situation but I can not wait Monday. Thats when I can really enjoy this macro as it is very busy and this will save me some time and nerves..

    Thank you again watersev!!!!


    Cheers
    Rain

  16. #16
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: Macro to loop through rows, if criteria is met then certain action is performed

    Hi watrsev. I tried the code with real data and encountered a bug. Please look the attached xls. On sheet "results" I have highlighted x3 rows in (rows 2666-2666). Now these rows have been combined/concatenated together while they shouldn't been. These three problem lines have the following Unique ID values
    181024317810
    181025891310
    181026707810
    If in sheet "2011" you use filter -> custom->equals to on column C, and use the unique ID 181024317810 you can see the following

    -------col C ------------------------------------col F----------------------------------------------Col G
    181024317810------------RN-207573, RN-207582------------------------------------------10
    181024317810------------RN-207582----------------------------------------------------------5

    So we know it should keep the top line and delete the lower line
    But on result screen the macro will combine them together like this

    -------col C ------------------------------------col F----------------------------------------------Col G
    181024317810------------RN-207582, RN-207573, RN-207582------------------------15
    And I don't understand why as it was working before.

    Can you have a look and see whats wrong. Currently the macro bears name convert in module 4
    Attached Files Attached Files
    Last edited by rain4u; 04-16-2011 at 03:26 PM.

  17. #17
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Macro to loop through rows, if criteria is met then certain action is performed

    a leading space caused a problem, corrected, please check, module 4, code "convert_short"
    Attached Files Attached Files

  18. #18
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: Macro to loop through rows, if criteria is met then certain action is performed

    Thank you, I will be testing as much as possible over the weekend. Cant wait to use it at work. I feel like a child who just got a candy!!! hehe

  19. #19
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: Macro to loop through rows, if criteria is met then certain action is performed

    Hi watersev.
    I was using the code at work and kept eye on it to test it. There is a bug with shorter version of the code. the following example.

    181026822610--------- RN-227589--------- 24
    181026822610--------- RN-227589--------- 24
    181026822610--------- RN-227648--------- 6

    It should produce
    181026822610--------- RN-227648, RN-227589--------- 30


    But currently produces
    181026822610--------- RN-227589--------- 24



    We did have a similar bug with previous iteration and you had it fixed. Can you fix it again with this new shorter and improved code.
    File with real data and error attached. If you run convert_short in module 4 it will reproduce the error.


    Cheers
    Rain
    Attached Files Attached Files

  20. #20
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Macro to loop through rows, if criteria is met then certain action is performed

    check attachment
    Attached Files Attached Files

  21. #21
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: Macro to loop through rows, if criteria is met then certain action is performed

    Bug fixed. Thank you!

  22. #22
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: Macro to loop through rows, if criteria is met then certain action is performed

    Hi Watersev
    I hope you can help me to make an adjustment or add feature to current code. I didn't realize that it can be important to capture one aspect of data until very recently when we were in bit of dispute with one of our suppliers. Capturing additional data could benefited us as we would known that we had caused a mistake ourselves when booking in some parts with wrong quantities. So it wasn't our supplier mistake as we wrongly accused them. So this is the feature I would like to add to the existing code.

    I want to keep everything exactly the same way as it is at the moment (it works without any errors) but I would like it to capture the quantities information.

    So every time the code takes the RN numbers and places them together on one cell on the same line I still want it to do the same thing but include the quantity information from column I.
    The current code changes this:

    -------col C ------------------------------------col G----------------------------------------------Col I
    181026716910------------RN-207380----------------------------------------------------------1
    181026688710------------RN-207090----------------------------------------------------------1
    181026688810------------RN-207343----------------------------------------------------------1
    181026699410------------RN-207209----------------------------------------------------------1
    181026699410------------RN-207210----------------------------------------------------------1
    181026699410------------RN-207211----------------------------------------------------------1
    181026713110------------RN-207418----------------------------------------------------------1
    181026712910------------RN-207412----------------------------------------------------------1


    to this:
    -------col C ------------------------------------col G----------------------------------------------Col I
    181026716910------------RN-207380----------------------------------------------------------1
    181026688710------------RN-207090----------------------------------------------------------1
    181026688810------------RN-207343----------------------------------------------------------1
    181026699410------------RN-207209, RN-207210, RN-207211------------------------3
    181026713110------------RN-207418----------------------------------------------------------1
    181026712910------------RN-207412----------------------------------------------------------1

    Now I would like code capture more information and change it to this instead the example above


    -------col C ------------------------------------col G--------------------------------------------------------------------------------------------Col I
    181026716910------------RN-207380--------------------------------------------------------------------------------------------------------1
    181026688710------------RN-207090--------------------------------------------------------------------------------------------------------1
    181026688810------------RN-207343--------------------------------------------------------------------------------------------------------1
    181026699410------------RN-207209 - QTY 1, RN-207210 - QTY 1, RN-207211 - QTY 1--------------------------------------3
    181026713110------------RN-207418--------------------------------------------------------------------------------------------------------1
    181026712910------------RN-207412--------------------------------------------------------------------------------------------------------1

    So the only amendments would be the ones in Green. Everything else should stay exactly as per current code as its working very efficiently and without any bugs.
    I have attached spreadsheet that contains the current code and example sheet called "After". There are 2 example rows there. One is on row 199 the other one is row 200. Macro is s "convert short" which is in module 4.

    I'm not sure how easy or hard it will be to add this feature in. I didn't even try to do myself as I'm very scared to destroy this bug free code.
    I would be very thankful if you can have a look of the code.


    Cheers
    Rain
    Attached Files Attached Files
    Last edited by rain4u; 05-29-2011 at 05:39 PM.

  23. #23
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Macro to loop through rows, if criteria is met then certain action is performed

    hi, rain4u, what does this comment mean in cell F211 sheet "After":
    "All yellow higlighted RN numers stay the same without QTY's. Qtys will only be added if Rn numbers should "
    Are there any additional conditions on adding quantity values?

  24. #24
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: Macro to loop through rows, if criteria is met then certain action is performed

    Hi watersev
    Please ignore the comment in in cell F211. I didn't know how to explain it very well and I think I made it more confusing. But what it means is that all the the cells that normally are kept untouched as per current code should also be kept untouched with new ammended code.

    Let me give an example.
    I would like the code change this:
    -------col C ------------------------------------col G----------------------------------------------Col I
    181026716910------------RN-207380----------------------------------------------------------1
    181026688710------------RN-207090----------------------------------------------------------1
    181026688810------------RN-207343----------------------------------------------------------1
    181026699410------------RN-207209----------------------------------------------------------1
    181026699410------------RN-207210----------------------------------------------------------1
    181026699410------------RN-207211----------------------------------------------------------1
    181026713110------------RN-207418----------------------------------------------------------1
    181026712910------------RN-207412----------------------------------------------------------1

    into this:

    -------col C ------------------------------------col G--------------------------------------------------------------------------------------------Col I
    181026716910------------RN-207380--------------------------------------------------------------------------------------------------------1
    181026688710------------RN-207090--------------------------------------------------------------------------------------------------------1
    181026688810------------RN-207343--------------------------------------------------------------------------------------------------------1
    181026699410------------RN-207209 - QTY 1, RN-207210 - QTY 1, RN-207211 - QTY 1--------------------------------------3
    181026713110------------RN-207418--------------------------------------------------------------------------------------------------------1
    181026712910------------RN-207412--------------------------------------------------------------------------------------------------------1

    but I wouldn't want the code change it into this: (see the the purpled lines. This is what i don't want it to do)

    -------col C ------------------------------------col G--------------------------------------------------------------------------------------------Col I
    181026716910------------RN-207380 - QTY 1 --------------------------------------------------------------------------------------------------------1
    181026688710------------RN-207090 - QTY 1 --------------------------------------------------------------------------------------------------------1
    181026688810------------RN-207343 - QTY 1 --------------------------------------------------------------------------------------------------------1
    181026699410------------RN-207209 - QTY 1, RN-207210 - QTY 1, RN-207211 - QTY 1--------------------------------------------------3
    181026713110------------RN-207418 - QTY 1 --------------------------------------------------------------------------------------------------------1
    181026712910------------RN-207412 - QTY 1 --------------------------------------------------------------------------------------------------------1

    So another words. It only needs to add this quantity information for the lines where the old code was adding the RN numbers together. I hope this is a better explanation. I quite didn't know how to explain. If the amended code will return exactly the same result as on sheet "after" then it should be correct. Thank you for looking into this.

    Cheers
    Rain
    Last edited by rain4u; 06-03-2011 at 08:49 AM.

  25. #25
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Macro to loop through rows, if criteria is met then certain action is performed

    hi, Rain, please check attachment if it does what you need, the code is module named "test", code "convert_short_plus". Hope this helps.
    Attached Files Attached Files

  26. #26
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: Macro to loop through rows, if criteria is met then certain action is performed

    Hi watersev.
    Thank you for trying to help me. I'm not sure if I'm doing everything correctly but it doesn't populate anything to sheet "results". I tried to run the macro as always: I opened the file -> tools -> macros-> macros->selected "convert_short_plus" and pressed run. You can see that the the screen flickers for a millisecond but nothing else happens. Sheet results remains blank. Does it work on your computer and populates information to results sheet?

    Thank you for helping me.
    Cheers
    Rain

  27. #27
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Macro to loop through rows, if criteria is met then certain action is performed

    hi, Rain, sorry for that, it was my misprint here:

    Please Login or Register  to view this content.
    It should be this and result goes out:

    Please Login or Register  to view this content.
    Attached Files Attached Files

  28. #28
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: Macro to loop through rows, if criteria is met then certain action is performed

    New feature works brilliantly but now there is a small bug. Let me demonstrate.

    On sheet "2011", data is like this:

    -------col C ------------------------------------col G--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Col I
    181026437410 ------------ RN-211621-1, RN-211622-1, RN-211623-1, RN-211626-1, RN-211627-1, RN-211628-1, RN-211629-1 --------------------------------------------------------------------------------------------------------------- 7
    181026437410 ------------ RN-211621 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1
    181026437410 ------------ RN-211622 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1
    181026437410 ------------ RN-211623 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1
    181026437410 ------------ RN-211626 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1
    181026437410 ------------ RN-211627 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1
    181026437410 ------------ RN-211628 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1
    181026437410 ------------ RN-211629 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1


    With current macro on after running it it returns the following on sheet "results":
    -------col C ------------------------------------col G-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Col I
    181026437410 ------------ RN-211621-1, RN-211622-1, RN-211623-1, RN-211626-1, RN-211627-1, RN-211628-1, RN-211629-1, RN-211621-1, RN-211622-1, RN-211623-1, RN-211626-1, RN-211627-1, RN-211628-1, RN-211629-1 -- 14


    While it should look like this:

    -------col C ------------------------------------col G--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Col I
    181026437410 ------------ RN-211621-1, RN-211622-1, RN-211623-1, RN-211626-1, RN-211627-1, RN-211628-1, RN-211629-1 --------------------------------------------------------------------------------------------------------------- 7

    So in effect the current code adds them to this PO 181026437410 but it shouldn't as it already contains those RN numbers.

    New spreadsheet attached contains this example.

    Can you have a look oh it when you have some free time?


    Many thanks
    Rain
    Attached Files Attached Files
    Last edited by rain4u; 06-03-2011 at 08:47 AM.

  29. #29
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Macro to loop through rows, if criteria is met then certain action is performed

    hi, Rain, please check attachment, run code "convert_short_plus"

    To recreate the bug you wrote about, I've added grey-coloured rows at the end of data data table on 2011 sheet.
    Attached Files Attached Files

  30. #30
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: Macro to loop through rows, if criteria is met then certain action is performed

    Looks to be working. I will test it thoroughly in the morning. Thank you for helping me. This renewed code will help to store more info which is great. I will let you know If its perfect like the old code.


    Cheers
    Rain

  31. #31
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: Macro to loop through rows, if criteria is met then certain action is performed

    Hi watersev.
    Just to let you know the code works perfectly with no more bugs found.
    Thank you!

+ 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