Match two tables using unique ID number

I have two tables using item number as the identifer  for each row. It is 
possible that their are items in either tables that do not match the other 
table. I need to match the two tables so that each unique item is in the same 
row and unique items in each table are on a seperate row.
0
8/17/2005 6:06:02 PM
excel.misc 78881 articles. 5 followers. Follow

1 Replies
247 Views

Similar Articles

[PageSpeed] 7

So you only care about the key identifier columns???

If yes, create a new worksheet.
Copy the key column from the first worksheet into column A.
copy the key column from the second worksheet into column B.

Add headers to row 1 (if you don't have them already).

Then run this macro:

Option Explicit
Sub testme()

    Application.ScreenUpdating = False
      
    Dim wks As Worksheet
    Dim ColA As Range
    Dim ColB As Range
    Dim iRow As Long
    Dim myCols As Long
    
    Set wks = Worksheets("sheet1")
    wks.DisplayPageBreaks = False
    With wks
        'row 1 has headers!
        Set ColA = .Range("a2", .Cells(.Rows.Count, "A").End(xlUp))
        Set ColB = .Range("b2", .Cells(.Rows.Count, "B").End(xlUp))
                
        With ColA
            .Sort key1:=.Cells(1), order1:=xlAscending, header:=xlNo
        End With
       
        'change the mycols to the number of columns that
        'are associated with column B
        
        myCols = 1 ' columns B only
        With ColB.Resize(, myCols)
            .Sort key1:=.Cells(1), order1:=xlAscending, header:=xlNo
        End With
        
        iRow = 2
        Do
            If Application.CountA(.Cells(iRow, "A").Resize(1, 2)) = 0 Then
                Exit Do
            End If
            
            If .Cells(iRow, "A").Value = .Cells(iRow, "B").Value _
             Or Application.CountA(.Cells(iRow, "A").Resize(1, 2)) = 1 Then
                'do nothing
            Else
                If .Cells(iRow, "A").Value > .Cells(iRow, "B").Value Then
                    .Cells(iRow, "A").Insert shift:=xlDown
                Else
                    .Cells(iRow, "B").Resize(1, myCols).Insert shift:=xlDown
                End If
            End If
            iRow = iRow + 1
        Loop
    End With
    
    Application.ScreenUpdating = True
    
End Sub


If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm


fisherman wrote:
> 
> I have two tables using item number as the identifer  for each row. It is
> possible that their are items in either tables that do not match the other
> table. I need to match the two tables so that each unique item is in the same
> row and unique items in each table are on a seperate row.

-- 

Dave Peterson
0
petersod (12004)
8/18/2005 1:36:38 AM
Reply:

Similar Artilces:

Add Invoice Number to Report
I have created a delivery table that contains all of the usual fields , Pickup, Delivery, Billing, NoPeices, Weight... etc. The table is updated with current delivery information daily. At the end of the week I create a report grouped on Billing customer that prints an invoice with all of the unprinted deliveries the customer is paying for... the report works fine. What I need to figure out is how to assign a unique invoice number (autonumber) to the report that will be associated with each Billing customer for that print period. Can I somehow generate a unique number at the time I ...

How to use outlook address in Excel
Hello, I have an Excel sheet which I use as an invoicing-application. I would like to retrieve address-data from Outlook where I keep all my contact-data of my customers. So, I want to select a customer from my Outlook contactlist when I am writing a new invoice in Excel. In Word, I have a macro which does this, but unfortunately the Application.GetAddress does not work in Excel. Can somebody help me ? "Henny Slokker" wrote: > Hello, > > I have an Excel sheet which I use as an invoicing-application. I would like > to retrieve address-data from Outlook where I...

Add SafePay footer record for date and account number
Union Bank of California has a Positive Pay format that requests a footer record for each day and account number. So if you transmit checks issued on two dates for a single account, the SafePay file would have two footer records--one for each date. Currently, I am only able to create a footer by account, totalling all checks issued for that account (regardless of date), and attributing that total to the Issue Date in the footer record. Union Bank reads the issue date on the footer, and sees that the checks issued on that date do not match the footer total, causing them to consider th...

IE8 uses 95+% of cpu after update to sp3
I just updated to XP sp3 and did updates after that and IE8 is running so slow. I loaded task manager to see what was happening and IE8 was using up to 99%. My system was a slow XP sp2 but did a disk clean and defrag and it was running a lot faster. Apps load and run faster after sp3 but not IE8. Thanks for any suggestions mx5 wrote: > I just updated to XP sp3 and did updates after that and IE8 is > running so slow. I loaded task manager to see what was happening > and IE8 was using up to 99%. > > My system was a slow XP sp2 but did a disk clean and defrag and...

assign numeric value to letters and sum with other numbers
I apologize if I am duplicating an earlier question, but I can't find the answer. How do I sum a row or column that has numbers and letters by giving the letters a numerical equivalent? -- WJG On Mon, 11 Jan 2010 12:19:01 -0800, Galadad <Galadad@discussions.microsoft.com> wrote: >I apologize if I am duplicating an earlier question, but I can't find the >answer. How do I sum a row or column that has numbers and letters by giving >the letters a numerical equivalent? Could you give an example of input and expected output. Lars-�ke Just guessing...

Calculated fields in Pivot Tables
Is it possible to use an "if" formula when creating a calculated field? I have an existing field in my pivot table called commissions and I want to create a new field that will give me a 1 if for each row if commissions are over 4 and a 0 if they are under 4. Is this possible? What is the formula? It seems ok Try something like : =IF(Commissions>=4,1,0) -- Rgds Max xl 97 --- Singapore, GMT+8 xdemechanik http://savefile.com/projects/236895 -- "lj" <lj@spu.edu> wrote in message news:1132008509.143327.194520@g47g2000cwa.googlegroups.com... > Is it possible to u...

VB: using a string to set a range object?
I'm a bit new to the excel "range" object type. I was suprised to see that while I can do: dim chunk as Range chunk = .Range(A5:B6) I apparently cannot do: dim chunk as Range dim stuff as string string = "A5:B6" chunk= .Range(string) How can I concatenate up a string describing a range, and then use it to define a range object's target cells? - Ross. Oops, I meant chunk = .Range("A5:B6") in the first example - I forgot the quotes. R. "RGK" <nothanks@nospam.go> wrote in message news:RqydnSWzbu_OEZbeRVn-2A@...

How to use CSplitterWnd for Dynamic Nested Splitter window?
Using VC++ (.NET) I am trying to implement a Dynamic Nested Splitter window using CSplitterWnd. I haven't found any documentation that explains how to get this to work properly and the only examples I have found also do not work properly. There are plenty of examples of Static Nested Splitter windows, but I need an example of a Dynamic one. The static splitter windows won't work for my requirements. Are there any examples or documentation that explains how to properly implement a Dynamic Nested Splitter Window using CSplitterWnd? Thanks, Dave Hi Dave, > Using VC++ (.NE...

Add phone number to quote report.
Hey guys, My retail staff asked me if it is possible to add the customer phone number to the Quote summary or Quote detailed report. Does anyone know what changes need to be made to the report to make this happen. I know I will have to change the query and add a join statement to get it from the customer record but am unable to figure out how to do it. Any ideas? Thanks, Nevermind, I figured it out myself. Thanks anyway. <nick@realkiteboarding.com> wrote in message news:BhKXd.15130$GO5.11570@fe07.lga... > Hey guys, > > My retail staff asked me if it is possible to a...

Coding Convention for using Binary FlagWords?
Hi all --- I'm thinking of putting the .Tag property to use by using a binary ("bitwise") encoded flag word. Over time I've come across different possible uses for .Tag but have never standardized how I use it. Has someone developed a convention for "parsing" binary flag words? A simple IF works if I only need to test for one flag, but if I need to check for the presence of multiple bits the only construct that comes to mind is a series of IF statements .... something along the lines of: Enum FlagWord FlagA = 1 FlagB = 2 FlagC = 4 .......

How do i locate the point of intersection of two lines graphs
I have a plot of two lines using excell which intersect at a point. I want to locate the point of their intersection using excell and show the co-ordinates of that point so that any body can see that i read that point from it. Step by step procedurewould be helpful and i am using microsoft excel 2007. Thanks. I will assume you have two straight lines - if not please tell me what they are. Let the lines follow the two functions y1=m1x1+b1 and y2=m2x2+b2 Let the point of intersection be Y and X Then m1X+b1=m2X+b2, giving X=(b2-b1)/(m1-m2) In Excel terms, X=(INTERCEPT(y-values2,x-values2)...

Using Outlook client for CRM 3.0 in a remote office
I need to set up access to the corporate CRM from several remote offices. All of them have VPN connections (Windows or Checkpoint). What are the steps required to configure remote clients to be able to use CRM features in Outlook. Remote users can connect to CRM through Internet Expolorer. Thanks. Assuming they are connected, the isntallation over a VPN connection should not be any different than a typicaly installation. If the connection is slow though, the first synch & Go Offline process will be noticiably slower though. -- Matt Parks MVP - Microsoft CRM "mkatsev"...

pivot table subtotals
I'm stuck trying to develop subtotals in a pivot table. I hav successfully placed Sums of the individual elements, but I'd like "Subtotal" line for specific types of elements i.e.: 1/22 1/23 1/24 Group1 Apples Oranges Pears Group1 Sum Group2 Corn Carrots Beans Group2 Sum Grand Total All of thee above rows/lines calculate just fine except the GroupX Su lines? Does anyone have any suggestions on how I can get subtotals to wor correctly? Do -- Message posted from http://www.ExcelForum.com Double-click on the field button at the top of the Group column. Un...

using std::deque in multiple threads
I have a thread that listens on a message queue and populates a std::deque with events from that message queue, but only holds the latest 100. In my main thread, I want to populate a listbox with the information from that deque. So, it ends up being that one thread can add/remove items from the deque while another thread is trying to iterate through them. How can I make this thread-safe? Thanks, PaulH The code looks a bit like this: std::deque<MESSAGE_TYPE> m_dequeMessages; CMyClass::MessageThread() { //... while (ReadMsgQueue(hMsgQueue, &msg,...)) { m_dequeMessages.pu...

Use a wildcard within edit/replace
Hello Is there a method of using a wildcard function within edit/replace (in Excel 2003) so that I can tweak the way a formula works? The example I have is the following formula =IF(ISERROR(VLOOKUP($A8,DataImport!$A:$J,5,FALSE)),"",VLOOKUP($A8,DataImport!$A:$J,5,FALSE)) which I would like to change to =IF(ISERROR(VLOOKUP(TEXT($C8,"0000),DataImport!$D:$E,2,FALSE)),"",VLOOKUP(TEXT($C8,"0000"),DataImport!$D:$E,2,FALSE)) The issue is (I think) that this formula is repeated many times over in one column over a number of worksheets - therefo...

Wordwrapping a long sentence using F2, how to end the process?
Using Excel 2002...I pasted in a long sentence, and it goes off the right side of the screen. I know that I can make it word wrap by hitting F2. I've done that and it works nicely. But I was told that I could end this process by hitting Alt-Enter, and that doesn't work... all that happens after Alt-Enter is a blank new row opens up below the word-wrapped rows. If I hit Alt-Enter again, another blank row opens up below. How can I end this F2 word-wrap and go on with other business. John alt-enter is used to force a new line in a cell. If you want to wrap the text a...

excel 2000 message
excel 2000 message - 'cannot use object linking and embedding' Were they hit by the MSBlast worm? One poster (Lutz Meyer) guessed that this was the cause of his problems. I haven't seen any confirmation/denial, but you may want to read his post: http://groups.google.com/groups?threadm=3F3971AF.FA4490F5%40msn.com Post back with your results. I'm curious if that was the problem. (It's come up quite a few times since MSBlast hit.) bill bootle wrote: > > excel 2000 message - 'cannot use object linking and > embedding' -- Dave Peterson ec35720@msn.c...

Number Format Problem Prevents Proper Sorting
I have a long list of numbers that were exported from anothe application that I can't seem to format properly to sort in ascendin order. I have changed the format from General to Number and back wit no success. I'm sure that this is an easy fix, but I'm not seeing th answer. The third entry below (1103) should be toward the top of th list. Any ideas? 110272 110277 1103 110329 110338 11033 -- 65Stan ----------------------------------------------------------------------- 65Stang's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1500 View this threa...

Mobile using up CPU
Hi there Since we installed CRMMobile our (new) server has been SO SLOW! SqlServer is taking anywhere from 69 - 99% cpu time (mostly around 99) I have run sql profiler and discovered that many times a second the following transactions are running: exec sp_executesql N'SELECT recipientAddr,recipientSrvcPort,sourceAddr,sourceSrvcPort, MIN(arrivalDate) as minArrivalDate, count(*) as messageCount FROM vwInBoundQueue WHERE recipientAddr=@recipientAddr AND recipientSrvcPort=@recipientSrvcPort GROUP BY sourceAddr,sourceSrvcPort,recipientAddr,recipientSrvcPort ORDER BY minArrivalDat...

how can i start using excel for the first time?
i cant figure out how to get excel to work for me and im a first time user of it? i Cant get nothing to work on it? can anyone please help me here Paul Can you get Excel to start up? Can you get a blank workbook to open via File>New? For basics on Excel see.......... http://www.usd.edu/trio/tut/excel/index.html http://www.baycongroup.com/el0.htm Microsoft Training Courses. http://office.microsoft.com/en-us/training/CR061831141033.aspx Gord Dibben Excel MVP On Wed, 15 Dec 2004 15:39:02 -0800, "Paul Scheffer" <Paul Scheffer@discussions.microsoft.com> wrote: >i ...

File in use .... is locked for editing
Please help. In Microsoft Excel 2000, we seem to be getting the above error message frequently. No other users are in the file, and there aren't any temporary files relating to the file in question. Any ideas on what is causing this? We are running a mixture of Windows 2000 & XP machines on to a Small Business Server 2000. Hope to hear from someone soon Regards Simon I think you killed the usual answer of cleaning the temp folder. But have you rebooted? Maybe there's a hidden instance of excel running that "owns" the file. And if the file/workbook is on a net...

Counting Blank Cells in Pivot Table
How do I have a Pivot Table count the blank cells as well as the other cells? The Pivot table I created counts everything that had data (A, B, C, D, etc...) but does not count the blank cells. Thank you, Jack As answered in microsoft.public.excel.charting: To count the blanks you could use a space character, or the formula ="", in the source data, instead of leaving the cells blank. The pivot table will be able to count those. Jack wrote: > How do I have a Pivot Table count the blank cells as well > as the other cells? The Pivot table I created counts > everythi...

Specify data for use in FRx pivot tables
How do I specify what data fields appear in an Excel pivot table (or ..cub file) from FRx? I want to export the natural account number into the pivot table to sort on. TIA ...

using $ in a formula
when in a cell and I type: =$C4, what does that mean vs =C4? Also what does =$C$4 mean vs =C$4? what is the significance of the dollar sign? Thanks Hi Robin it changes the addressing from relative to absolute e.g. if i have in cell C1 the formula =A1*B1 and i fill it down to C2 the formula will change to =A2*B2 or if i fill it across to D1 the formula will change to =B1*C1 - this is relative addressing and is the default in excel however sometimes you want to "fix" the cell reference in a formula and this is where the $ come in =A1*$B$1 filled down from C1 to C2 will change ...

Formatting Phone Numbers
Consider this example: A1 -> 3365551111 A2 -> 336-555-2222 A3 -> (336) 555-3333 I want to be able to scan through column A and change all numbers to be in the format of A1 which is just straight numbers...no punctuation. How would I do that? -- Tha BeatMaker ------------------------------------------------------------------------ Tha BeatMaker's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=23998 View this thread: http://www.excelforum.com/showthread.php?threadid=383980 Easiest would be to use a macro. Sub RemoveAlphas() ''...