Results 1 to 7 of 7

Thread: [RESOLVED] Useful two table line up excel

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    393

    Resolved [RESOLVED] Useful two table line up excel

    Hi experts - just want to match two tables side by side lined up by certain fields.

    Sheet names list

    Start with - contains the start with data (note could be any length - not lined up but some could be line up already or may not be lined up at all)

    Two table line up - contains a sample example of what the startwith data should look like after the code is
    run in the output two table line up sheet.

    Supporting info - if not clear is explained under the supporting info explanataion.

    Any ideas of how this could be done as I'm struggling. All info should be in the spreadsheet attached by the viusal pattern between start with amd two table line up. Also supporting info gives a more descriptive explanation.

    Much appreciated.
    Attached Files Attached Files
    Last edited by gphillips; Oct 20th, 2006 at 03:53 PM.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Useful two table line up excel

    this seems to work with the limited data in the test sheet, but it maybe neccessary to run another similar evaluation to check the values of item parts when the ref is the same
    VB Code:
    1. i = 3
    2. Do Until i = ActiveSheet.UsedRange.Rows.Count
    3.         If Cells(i, 1) > Cells(i, 9) Then
    4.             Range(Cells(i, 1), Cells(i, 4)).Insert xlDown
    5.            
    6.         ElseIf Cells(i, 1) < Cells(i, 9) Then
    7.             Range(Cells(i, 9), Cells(i, 13)).Insert xlDown
    8.            
    9.         End If
    10.         i = i + 1
    11. Loop
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    393

    Re: Useful two table line up excel

    Hi,

    Thanks for this. Very clever!!!!! Few points first of all, the original code doesn't work for the attached scenario.

    It just loops on forever to the bottom of the spreadsheet. Ref/part could be string or numeric.
    One table could also have more records than another.

    Also I am trying to get the complete solution I have posted my attempt. Please note both ref and part are the lining up mechanisms combined but this doesn't work either - it just loops on forever.


    VB Code:
    1. i = 3
    2. Do Until i = ActiveSheet.usedrange.Rows.Count
    3.         If Cells(i, 1) > Cells(i, 9) Or _
    4.             Cells(i, 2) > Cells(i, 10) Then
    5.             Range(Cells(i, 1), Cells(i, 4)).Insert xlDown
    6.  
    7.         ElseIf Cells(i, 1) < Cells(i, 9) Or _
    8.         Cells(i, 2) < Cells(i, 10) Then
    9.             Range(Cells(i, 9), Cells(i, 13)).Insert xlDown
    10.  
    11.         End If
    12.         i = i + 1
    13. Loop


    Cheers once again.
    Attached Files Attached Files

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Useful two table line up excel

    try this
    VB Code:
    1. Sub lineup()
    2. i = 3
    3. Do Until i = ActiveSheet.UsedRange.Rows.Count
    4.     If Not IsEmpty(Cells(i, 1)) And Not IsEmpty(Cells(i, 9)) Then
    5.         If Cells(i, 1) > Cells(i, 9) Then
    6.             Range(Cells(i, 1), Cells(i, 4)).Insert xlDown
    7.            
    8.         ElseIf Cells(i, 1) < Cells(i, 9) Then
    9.             Range(Cells(i, 9), Cells(i, 13)).Insert xlDown
    10.         ElseIf Cells(i, 1) = Cells(i, 9) Then
    11.             If Cells(i, 2) > Cells(i, 10) Then
    12.                 Range(Cells(i, 1), Cells(i, 4)).Insert xlDown
    13.             ElseIf Cells(i, 2) < Cells(i, 10) Then
    14.                 Range(Cells(i, 9), Cells(i, 13)).Insert xlDown
    15.             End If
    16.            
    17.         End If
    18.     End If
    19.         i = i + 1
    20.        
    21. Loop
    22. End Sub
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    393

    Re: Useful two table line up excel

    Hi,

    Getting there, for some reason , it does not work if the very bottom ones are different on both tables are different.
    It seem to get lost at the very bottom few lines. try changing a few
    Any ideas

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Useful two table line up excel

    dunno, try this
    VB Code:
    1. Do Until i > ActiveSheet.UsedRange.Rows.Count

    or add a couple of extras to the rows count
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    393

    Re: Useful two table line up excel

    Top man, 5 star rating for this stanadard useful tool.
    It works if you add plus 1 on end of code above!

    Thanks very much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width