+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: Find and Insert Intersecting Values

  1. #1
    Valued Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    639

    Find and Insert Intersecting Values

    Hi all, not sure how I can do this.
    I have a spreadsheet named: PartNumVsJobNum
    The rows, from row 3 down in column A contain part numbers.
    The Columns, in row1, from B to (last column with data) contains job numbers.

    On another sheet, named: Non_Completed. I have the part numbers in column A (as in the PartNumVsJobNum worksheet). In column E down are
    Job Numbers (IE: 4PZ). In column G are quantity values.

    So for instance if Cell (A3) = 360010 (first part number listed)
    and Cell (B1) = 4PZ I need a macro the will find the rows with 360010
    in Column A on sheets( Non_Completed) and try to find the job number (4PZ)
    in (columnE) for one of the rows. If the job number is found, then the value
    in G of the (Non_Completed) sheets should be copied to the corresponding XY
    cell in the PartNumVsJobNum spreadsheet.

    I will need to do this for each job number on PartNumVsJobNum Sheet.

    I'm attaching a sample worksheet below.


    Any help is appreciated.

    Thanks,
    BDB
    Attached Files Attached Files

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Find and Insert Intersecting Values

    Hello BDB,

    I wrote this macro based on what you posted. I am not sure this what you intended because I saw several ways the data could be interpreted. At the very least, it is a starting point. A button has been added to the "Non Completed" sheet to run macro, which is shown below.
    Option Explicit
    
    Public Jobs As Object
    Public Parts As Object
    
    Sub LoadPartsAndJobs()
    
      Dim C As Long
      Dim ColRng As Range
      Dim Item As String
      Dim Key As String
      Dim R As Long
      Dim RngEnd As Range
      Dim RowRng As Range
      Dim Wks As Worksheet
      
        Set Wks = Worksheets("PartNumVsJobNum")
        
        Set RowRng = Wks.Range("A3")
        Set ColRng = Wks.Range("B1")
        
        Set Jobs = Nothing
        Set Parts = Nothing
        
          Set Parts = CreateObject("Scripting.Dictionary")
          Parts.CompareMode = vbTextCompare
          
          Set Jobs = CreateObject("Scripting.Dictionary")
          Jobs.CompareMode = vbTextCompare
          
          Do
            Key = Trim(RowRng.Offset(R, 0))
            If Key <> "" Then
              If Not Parts.Exists(Key) Then
                 Item = RowRng.Offset(R, 0).Row
                 Parts.Add Key, Item
                 R = R + 1
              End If
            Else
              Exit Do
            End If
          Loop
          
          Do
            Key = Trim(ColRng.Offset(0, C))
            If Key <> "" Then
              If Not Jobs.Exists(Key) Then
                 Item = Split(ColRng.Offset(0, C).Address(True, False), "$")(0)
                 Jobs.Add Key, Item
                 C = C + 1
              End If
            Else
              Exit Do
            End If
          Loop
          
    End Sub
    
    Sub Macro1A()
    
      Dim Job As Range
      Dim JobNums As Range
      Dim PartNum As String
      Dim Qty As Variant
      Dim RngEnd As Range
      Dim Wks As Worksheet
      
        LoadPartsAndJobs
        
        Set Wks = Worksheets("Non_Completed")
        
        Set JobNums = Wks.Range("$E$2")
        Set RngEnd = Wks.Cells(Rows.Count, JobNums.Column).End(xlUp)
        Set JobNums = IIf(RngEnd.Row < JobNums.Row, JobNums, Wks.Range(JobNums, RngEnd))
        
          For Each Job In JobNums.Cells
            PartNum = Trim(Wks.Cells(Job.Row, "A"))
            Qty = Trim(Wks.Cells(Job.Row, "G"))
            Worksheets("PartNumVsJobNum").Cells(Parts(PartNum), Jobs(Trim(Job))) = Qty
          Next Job
          
    End Sub
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Valued Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    639

    Re: Find and Insert Intersecting Values

    Leith, Thank you so much. This is exactly what I need it to do.
    However, when I tried to apply it to the spreadsheet where I first bring
    in the Job Numbers from a source sheet, the macro gets stalled while running.
    I'm not sure what's causing this to happen because the page set for "PartNumBsJobNum" looks identical to the sheet on the book you sent back
    with the working macro. I've attached another workbook to provide an example of the problem.

    I have one more request with the setup of the "PartNumBsJobNum. sheet.
    If it's not too much to ask,Can you fix this so the information being brought into "PartNumBsJobNum" start one more column to the right. The reason I
    as is because, I'd want to be in my QTY's in stock into Column A From the
    Non_Completed Sheet. These quantites are found in column R.

    I've attached another sheet, to show how it should look.



    Thanks for all of your help. It has really advanced my overall progress in bringing about my envisioned objectives I have with my workbook.

    BDB
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    639

    Re: Find and Insert Intersecting Values

    Leith, I've figured out how to adjust the macro to run with the part numbers in column B on sheets "PartNumVsJobNum". But after, inserting the worksheet into my actual workbook and placing the macro's into module 2 of the workbook, trying to run the macro's produces an Run-Time error'1004':application defined or object defined error. On debug, the following
    line gets highlighted:

    Worksheets("PartNumVsJobNum").Cells(Parts(PartNum), Jobs(Trim(Job))) = Qty
    I tried several tricks to try and isolate the issue. First, I tried using the unadulterated sheet from the working workbook you sent me.
    Next, I created a new workbook where I inserted the non_completed sheet from my actual workbook and the PartNumVsJobNum from your sent workbook,
    and Lastly replaced the non_completed sheet of the workbook you sent with the actual non_completed sheet, but to no avale, all attempts failed.

    I even tried adding ....

          Set Parts = CreateObject("Scripting.Dictionary")
          Parts.CompareMode = vbTextCompare
          
          Set Jobs = CreateObject("Scripting.Dictionary")
          Jobs.CompareMode = vbTextCompare
    ...to macro1a, which didn't help.

    Any help fixin' this error is appreciated.

    thnx.

    BDB
    Last edited by bdb1974; 10-08-2009 at 04:25 PM.

  5. #5
    Valued Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    639

    Re: Find and Insert Intersecting Values

    Leith,

    I found what's causing the Run-Time error'1004':application defined or object defined error.

    If a job number from the Non_completed sheets is not listed on the "PartNumVsJobNum" sheet, it will error.

    Can this be fixed so that i may have jobs numbers on the non_Completed sheet that will not be found on the "PartNumVsJobNum" sheet?

  6. #6
    Valued Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    639

    Re: Find and Insert Intersecting Values

    Just also wanted to note, fixin' the code will kill two birds with 1 stone.

    The following...
    However, when I tried to apply it to the spreadsheet where I first bring
    in the Job Numbers from a source sheet, the macro gets stalled while running.
    ... will be fixed too.

    I tested transposing only the job numbers from the project status sheet to
    the "PartNumVsJobNum" sheet that are found on the non_Completed and it
    works.

    Therefore,any help to
    fixe so that i may have jobs numbers on the non_Completed sheet that will not be found on the "PartNumVsJobNum" sheet
    is greatly appreciated.

    Thanks
    BDB

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Find and Insert Intersecting Values

    Hello BDB,

    Looks like I have some catching up to do. Can you post a copy of your current workbook?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  8. #8
    Valued Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    639

    Re: Find and Insert Intersecting Values

    Leith,

    Here it is.

    Run "Transpose..." button first
    Run "Run Macro" next.

    This will run just fine.
    Add a ficticious job number to the Non_Completed sheet and run.
    It will error.

    Thanks again for your help and replying back to me.

    BDB
    Attached Files Attached Files

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Find and Insert Intersecting Values

    Hello BDB,

    Maybe you aren't running the correct macro. I ran "Transpose" then ran "Macro1A" - no errors. The table looks fine.

    EDIT: Just checked the macro button. It is calling the correct macro.
    Last edited by Leith Ross; 10-09-2009 at 04:48 PM.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Find and Insert Intersecting Values

    Hello BDB,

    Am I looking for an error code or something in the data that is incorrect?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  11. #11
    Valued Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    639

    Re: Find and Insert Intersecting Values

    Yes, It will error.
    ...just add a new job # to the Non_Completed page and see what happens.
    Put in anything you like. example: 4TR or 9ZW in the job #column again
    it will go on sheet("Non_Completed").

    Thanks,

    BDB
    Last edited by bdb1974; 10-12-2009 at 03:10 PM.

  12. #12
    Valued Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    639

    Re: Find and Insert Intersecting Values

    Leith,

    I'm bumping this, hoping for you to take another look at this.

    Thanks,

    BDB

  13. #13
    Forum Guru jaslake's Avatar
    Join Date
    02-21-2009
    Location
    mineral city, ohio
    MS-Off Ver
    Excel 2007; Excel 2000
    Posts
    4,004

    Re: Find and Insert Intersecting Values

    Hi BDB
    I've followed this thread from the beginning and am amazed at the code Mr Ross developed for your issue. I understand you still have a problem
    Add a fictitious job number to the Non_Completed sheet and run.
    It will error.
    My question is "What do you wish to happen if a non-existent job number exists on the Non_Completed sheet". Do you want
    fixed so that i may have jobs numbers on the non_Completed sheet that will not be found on the "PartNumVsJobNum" sheet
    or do you want a test to make certain it does exist as a legitimate job number? Either can be done, just let me know what you wish to happen and I'll take a look at it for you.
    J
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  14. #14
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Find and Insert Intersecting Values

    Hello bdb1974,

    This latest workbook is very different in layout. To make this even more difficult you have included hyperlinks. I have no idea what data you want where now. I need more information than "It's broke. Can you fix it?"
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  15. #15
    Valued Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    639

    Re: Find and Insert Intersecting Values

    Bumpin.... hoping to work out a small glitch.

    Leith, in response to:

    This latest workbook is very different in layout. To make this even more difficult you have included hyperlinks. I have no idea what data you want where now. I need more information than "It's broke. Can you fix it?"
    The layout has not changed in regards from where the data is collected.
    Disregard the hyperlinks as this has been tested and does not affect the code you created.

    However, please let me state again.
    If, there are jobs on the source sheet (Non_Completed) that's not on the result sheet(PartNumVsJobNum), then the code hangs. It will never populate
    the quanities onto the field of the result (PartNumVsJobNum) sheet.
    If you can take the example book I posted, Add a ficticious job number.
    Lets say: 5ZZ to job column E on the (Non_Completed) sheet and place a ficticious QTY to that Qty Column G, you will see how the program will hang.


    I've been going over and over you code trying to decipher on what could possibly be causing the issue. I'm still having trouble trying to understand the mechanics of it , let alone start to try and fix it.

    Thanks again for all that you have done. There's no way I've could have accomplished so much on my own in such a short amount of time.

    BDB

+ 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.2.0