Results 1 to 31 of 31

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

Threaded View

  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.

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