+ Reply to Thread
Results 1 to 16 of 16

Find part and add values

  1. #1
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    Find part and add values

    Greetings again, Gurus.

    I don't know if this is even possible via VBA, but thought I'd throw it out there and see what you guys think.

    In the attached workbook column D contains fields for the UsagePN. If a part is "rolled-up" in our order system to a new part number, then the OLD part number, (in colmn B), is associated with a UsagePN. What I need to do is, for every part that has a UsagePN in Column D, I need to find that part number in column B and add the inventory values from the old part number to the new one.

    For Example:
    Row 74 in the attachment has a UsagePN of AC1230105V. I need to take the values from cells G74 thru K74 andd ADD them to the existing values in G77 thru K77, which are the inventory values for AC1230105V.

    In other words, since part number AC1230105 has rolled-up to the new part number AC1230105V, I need to add all of the inventory to the new part number, AC1230105V. After this is done for ALL parts with a usage part number, I will delete all the rows containing UsagePN's.

    Here's the catch, as you can see in the example, there is no consistency, so a simple formula like adding the values to the same part number with a "V" at the end won't work. I guess you would have to do something like for each row with a value in column D, dim that row so you can refer back to it, then search for a match in column B, insert a "helper" row below where the part number is found to add the quantities, then replace the original with the helper row, and then delete the helper. One of you guys probably knows a better way.

    Keep in mind that you won't always find a match, so the macro needs to continue to the next part if no match is found.

    I hope I was clear. This one looks like it will be a nightmare, but I hope somebody on here has some ideas.

    Thanks in advance for any help you can offer.
    Attached Files Attached Files
    Last edited by hutch@edge.net; 04-20-2009 at 04:34 PM.

  2. #2
    Forum Contributor
    Join Date
    04-24-2007
    Location
    NYC
    MS-Off Ver
    2k3/2k7/2010
    Posts
    270

    Re: Find part and add values

    I see you are trying to compare two values, one with a added suffix.
    If you know how many characters are used in the suffix you can use the ? for a wildcard if statement, else there's * for an unlimited value.

    Here's a example
    Please Login or Register  to view this content.
    you have to be careful though, the use of wildcard is under the assumption that the next change is going to be unique.

    If you use ?, have a 101a, and a 101b and are trying to compare it to 101. It will assume both are the same
    If you use *, have a 101abc, and 101ab and are trying to compare it to 101. it will assume both are the same

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

    Re: Find part and add values

    It might help any potential helpers if you could add to your example an (at least partial) illustration of your expected results.

  4. #4
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    Re: Find part and add values

    Thanks for the reply, slx.

    I don't think the wildcard approach will work, for the very reasons you mentioned. For example, rows 74 thru 78 in the attachment have the same initial part numbers, but the suffixes are all different. The plain part crosses to the "V" part, the "C" part crosses to the "PP" part, etc. This will often be the case.

    There will probably also be instances where the UsagePN is completely different from the original PN. Part number GM1225188 may roll up to GM1230145, or something like that.

    Any other suggestions on how to make this work?

  5. #5
    Forum Contributor
    Join Date
    04-24-2007
    Location
    NYC
    MS-Off Ver
    2k3/2k7/2010
    Posts
    270

    Re: Find part and add values

    Are you trying to match values in column D to values in column B? because if you are then it is a straight forward comparison the only thing u need to do is a nest looped that compares two different values on different rows.

  6. #6
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    Re: Find part and add values

    I am trying to ADD values for a part found in column D to the values of the same part found in column B. The values I am trying to add are in columns G thru K.

    does that make sense?

  7. #7
    Forum Contributor
    Join Date
    04-24-2007
    Location
    NYC
    MS-Off Ver
    2k3/2k7/2010
    Posts
    270

    Re: Find part and add values

    try this.
    Please Login or Register  to view this content.
    This says, As I go down column B, i am looking for this value in column D, if i find it, i'm put all values corresponding D to the B. Then delete D.

    I had it backwards before.
    Last edited by slx; 04-16-2009 at 04:25 PM.

  8. #8
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    Re: Find part and add values

    It looks like it may be working in my test, but if so it is deleting the wrong rows. It looks like it is deleting the NEW part number, (without a number in column D), when I need it to delete the OLD number, the one with the number in column D.

    When I tried to edit the script by commenting out "Rows(i2).Delete" it appears to have stuck the macro in an endless loop. I had to ctrl-alt-del to get out of Excel.

    How would I modify this to delete the OLD part number, so that I can test it further?

  9. #9
    Forum Contributor
    Join Date
    04-24-2007
    Location
    NYC
    MS-Off Ver
    2k3/2k7/2010
    Posts
    270

    Re: Find part and add values

    if change "i2" to "i", then your deleting the row with matching id on column B. otherwise your deleting the row with matching id on column D.
    Please Login or Register  to view this content.
    Take currently adds the value from column D to one in column B.
    if you change that i to i2, then it will instead add B to D.


    if you comment out the delete, the it will get stuck in a loop because it wont be able to get past that row. if you want it to continue. I suggest doing this
    Please Login or Register  to view this content.
    This way it wont recheck that same thing over and over.
    Last edited by slx; 04-16-2009 at 04:48 PM.

  10. #10
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    Re: Find part and add values

    I stand correctd, slx. After further testing, the script appears to be working perfectly as is. I was hopeing the code would be something I would recognize, so I could customize it to work on the full worksheet. I trimmed down my example worksheet to make it easier to understand, and to protect sensitive data.

    So, I've copied the code below as I'm using it, and notated it to show my understanding of it, could you, or someone, please let me know if I'm even close?

    Please Login or Register  to view this content.
    If there is anything you can do to help an idiot understand this script, and how it works, I would be greatly appreciative.

    Thanks.

  11. #11
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    Re: Find part and add values

    Good morning again, Gurus.

    After further testing on the code, on a larger sample file, there still appears to be some errors. The zipe file contains the sample file, with a worksheet both before and after running the macro. It also contains the macro as it is being used.

    One of the big errors I have noticed is that if 2 parts roll-up to the same part number, none of the data appears to be added.

    If anybody has a suggestion that would make this work, please post. Meanwhile, I'm going to start working on another method utilizing the subtotal command.

    Thanks for your time and efforts!
    Attached Files Attached Files

  12. #12
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    re: Find part and add values

    Aside from the fact that the code didn't appear to add the values if 2 parts rolled up to the same part number, I'm curious if this code would work if I ran it a 2nd time on the same data? Would the 2nd time through catch the 2nd instance of the part number? Why did the values not add to the roll-up number if there were 2 parts rolling up, but did if there was only 1?

    The reason I ask..., if we could get this code to work, and I could learn it well enough to modify it to meet various page layouts, as needed, this is a code I could probably use several times daily. I'm always comparing sales or inventory on thousands of part numbers, and needing to combine totals for parts where the earlier part number has been superceded.

    Again, thanks for the help so far, slx, and please let me know if you or anyone has an idea on how to make this code work.

    Hutch

  13. #13
    Valued Forum Contributor
    Join Date
    08-26-2006
    Location
    -
    MS-Off Ver
    2010
    Posts
    388

    re: Find part and add values

    The macro below, when run on your Original Data sheet with 517 rows of data reduces that to 454 rows after 63 UsagePn rows are deleted.

    The following UsagePns are not found:
    AC1006114
    AC1241105PP

    The code mainly uses the Find method (see example in VB Help) with Range objects and Offsets.
    Please Login or Register  to view this content.
    There will probably also be instances where the UsagePN is completely different from the original PN. Part number GM1225188 may roll up to GM1230145, or something like that.
    The code as it is won't handle exceptions.
    You would have to relate the 2 numbers somehow (maybe 2 lists of numbers on a sheet, or 2 arrays, or a userform with user input controls etc.) and amend the code as required.
    Last edited by T-J; 04-21-2009 at 12:25 PM. Reason: spotted error in code

  14. #14
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    Re: Find part and add values

    Thanks, T-J.

    In my limited testing, the code seems to work really well. I'll have to get some time to test on a larger sample size before I can tell for sure, and have to figure out how to handle the exceptions.

    Thanks for the help!!

  15. #15
    Valued Forum Contributor
    Join Date
    08-26-2006
    Location
    -
    MS-Off Ver
    2010
    Posts
    388

    Re: Find part and add values

    Hi hutch,

    Just to make you aware, I spotted a small error in the code above and have made an amendment.

    The 2 lines containing xlDown have been changed to xlUp (highlighted in red).

    The original code works ok, but was checking all cells in a column, the new code only checks up to the last row of data, so is more efficient.

    Good luck with the next part.

  16. #16
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    Re: Find part and add values

    Thanks again, T-J. I had noticed on a larger sample group that the macro was pretty slow. I'll give the revision a try and see if that speeds me up any. (I'm sure it will.)

    Thanks again!!

+ 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