| Home | Forums | Reviews | Articles | Register |
![]() |
| Thread Tools | Rate Thread |
|
|
|
| |
|
Bob Bridges
Guest
Posts: n/a
|
Well, let's work through it a piece at a time:
1) Get the user to name one or both files; there are various get-the-file-name dialogues out there, but GetOpenFilename is already built into Excel. (Or so it says here; I've never tired it, but I expect it's easy.) 2) Open both workbooks, of course, along with some error checking to be sure they're both there and both of the expected type. 3) You didn't say exactly what sort of comparison will be going on here, but the usual is a list in both workbooks of some item, each item uniquely identified by (say) student ID, part number, VIN, SSN, whatever. My own favorite way of identifying which items on one list are (or are not) to be found on the other uses the MATCH function in a helper column: =MATCH(RC1,'Other sheet'!C5,0) This gets me a list of row numbers for the items that are on the other sheet, and #N/A for each item that isn't. Usually I want to check both ways, but that's up to you; the point heer is that you'll put something like that MATCH formula up and down some column in one or both sheets, and after that your program can look at the results to cross-check all the items. 4) After that you can...well, you can do whatever you wanted your program to do. But maybe it's time to stop and let you ask more detailed questions, or maybe tell me I misunderstood your goal completely. --- "Brian" wrote: > I have two workbooks that I need to compare and then copy the data that is > missing from the original workbook (but present in the second one) into a > third new workbook. To complicate matters for every comparison the filename > of the workbooks to be compared chages. |
|
||
|
||||
|
Brian
Guest
Posts: n/a
|
Thanks a lot for the quick reply Bob.
It sounds like a was a bit vague in my original question. Your solution was helpful, but I am hoping to figure something out that is a bit more automated. I am trying to build a macro that can be used by anyone in my group so it needs to be a standalone spreadsheet. To start I've put in sFileName = Application.GetOpenFilename so they can then choose the 2 files ,which is working great! The files being compared are about fifty columns across, but each has a unique identifier in column C. Throughout the day we receive multiple of these files and need a quick way to find which rows are new. I was able to write a macro (which is below) that essentially compared row 1 in sheet 1 to row 1 in sheet 2 all the way down. This worked until there was one new row of data and then everything after that was considered "new/different" and was pulled into the output sheet. Is there anyway to write a formula that will recognize that a row exists in both sheets, even if the row letter numbers do not match, and therefore only pull out the rows that do not have a match in any other row? Dim wbkComp As Workbook Dim wbkWith As Workbook Dim wbkDiff As Workbook Dim shtComp As Worksheet Dim shtWith As Worksheet Dim shtDiff As Worksheet Dim lngCompRow As Long Dim lngDiffRow As Long Dim blnSame As Boolean Dim intCol As Integer Set wbkComp = Workbooks("Trade Blotter 2.xls") Set wbkWith = Workbooks("Trade Blotter 1.xls") Set wbkDiff = Workbooks.Add For Each shtComp In wbkComp.Worksheets Application.StatusBar = "Checking " & shtComp.Name Set shtWith = wbkWith.Worksheets(shtComp.Name) Set shtDiff = wbkDiff.Worksheets.Add shtDiff.Name = "Diff " & shtComp.Name lngCompRow = 1 lngDiffRow = 1 Do While shtComp.Cells(lngCompRow, 2) <> "" blnSame = True For intCol = 1 To 10 If shtComp.Cells(lngCompRow, intCol) <> shtWith.Cells(lngCompRow, intCol) Then blnSame = False Exit For End If Next If Not blnSame Then shtComp.Rows(lngCompRow).Copy shtDiff.Cells(lngDiffRow, 1) lngDiffRow = lngDiffRow + 1 End If lngCompRow = lngCompRow + 1 Loop Next Application.StatusBar = False Thanks a lot! Brian "Bob Bridges" wrote: > Well, let's work through it a piece at a time: > > 1) Get the user to name one or both files; there are various > get-the-file-name dialogues out there, but GetOpenFilename is already built > into Excel. (Or so it says here; I've never tired it, but I expect it's > easy.) > > 2) Open both workbooks, of course, along with some error checking to be sure > they're both there and both of the expected type. > > 3) You didn't say exactly what sort of comparison will be going on here, but > the usual is a list in both workbooks of some item, each item uniquely > identified by (say) student ID, part number, VIN, SSN, whatever. My own > favorite way of identifying which items on one list are (or are not) to be > found on the other uses the MATCH function in a helper column: > > =MATCH(RC1,'Other sheet'!C5,0) > > This gets me a list of row numbers for the items that are on the other > sheet, and #N/A for each item that isn't. Usually I want to check both ways, > but that's up to you; the point heer is that you'll put something like that > MATCH formula up and down some column in one or both sheets, and after that > your program can look at the results to cross-check all the items. > > 4) After that you can...well, you can do whatever you wanted your program to > do. But maybe it's time to stop and let you ask more detailed questions, or > maybe tell me I misunderstood your goal completely. > > --- "Brian" wrote: > > I have two workbooks that I need to compare and then copy the data that is > > missing from the original workbook (but present in the second one) into a > > third new workbook. To complicate matters for every comparison the filename > > of the workbooks to be compared chages. |
|
||
|
||||
|
Per Jessen
Guest
Posts: n/a
|
Hi Brian
You say that column C has a unique identifier, does that mean that a new entry is found if the identifier isn't found in both sheets, or do we need to compare several columns once we have found a identifier match ? Can the identifier be found more than once in column C ? Regards, Per On 14 Sep., 02:33, Brian <Br...@discussions.microsoft.com> wrote: > Thanks a lot for the quick reply Bob. > > It sounds like a was a bit vague in my original question. Your solution was > helpful, but I am hoping to figure something out that is a bit more > automated. I am trying to build a macro that can be used by anyone in my > group so it needs to be a standalone spreadsheet. > > To start I've put in sFileName = Application.GetOpenFilename so they can > then choose the 2 files ,which is working great! > > The files being compared are about fifty columns across, but each has a > unique identifier in column C. Throughout the day we receive multiple of > these files and need a quick way to find which rows are new. > > I was able to write a macro (which is below) that essentially compared row 1 > in sheet 1 to row 1 in sheet 2 all the way down. This worked until there was > one new row of data and then everything after that was considered > "new/different" and was pulled into the output sheet. > > Is there anyway to write a formula that will recognize that a row exists in > both sheets, even if the row letter numbers do not match, and therefore only > pull out the rows that do not have a match in any other row? > > Dim wbkComp As Workbook > * * Dim wbkWith As Workbook > * * Dim wbkDiff As Workbook > * * Dim shtComp As Worksheet > * * Dim shtWith As Worksheet > * * Dim shtDiff As Worksheet > * * Dim lngCompRow As Long > * * Dim lngDiffRow As Long > * * Dim blnSame As Boolean > * * Dim intCol As Integer > > * * Set wbkComp = Workbooks("Trade Blotter 2.xls") > * * Set wbkWith = Workbooks("Trade Blotter 1.xls") > * * Set wbkDiff = Workbooks.Add > > * * For Each shtComp In wbkComp.Worksheets > * * * * Application.StatusBar = "Checking " & shtComp.Name > * * * * Set shtWith = wbkWith.Worksheets(shtComp.Name) > * * * * Set shtDiff = wbkDiff.Worksheets.Add > * * * * shtDiff.Name = "Diff " & shtComp.Name > * * * * lngCompRow = 1 > * * * * lngDiffRow = 1 > * * * * Do While shtComp.Cells(lngCompRow, 2) <> "" > * * * * * * blnSame = True > * * * * * * For intCol = 1 To 10 > * * * * * * * * If shtComp.Cells(lngCompRow, intCol) <> > shtWith.Cells(lngCompRow, intCol) Then > * * * * * * * * * * blnSame = False > * * * * * * * * * * Exit For > * * * * * * * * End If > * * * * * * Next > * * * * * * If Not blnSame Then > * * * * * * * * shtComp.Rows(lngCompRow).Copy shtDiff.Cells(lngDiffRow, 1) > * * * * * * * * lngDiffRow = lngDiffRow + 1 > * * * * * * End If > * * * * * * lngCompRow = lngCompRow + 1 > * * * * *Loop > * * Next > * * Application.StatusBar = False > > Thanks a lot! > > Brian > > > > "Bob Bridges" wrote: > > Well, let's work through it a piece at a time: > > > 1) Get the user to name one or both files; there are various > > get-the-file-name dialogues out there, but GetOpenFilename is already built > > into Excel. *(Or so it says here; I've never tired it, but I expect it's > > easy.) > > > 2) Open both workbooks, of course, along with some error checking to besure > > they're both there and both of the expected type. > > > 3) You didn't say exactly what sort of comparison will be going on here, but > > the usual is a list in both workbooks of some item, each item uniquely > > identified by (say) student ID, part number, VIN, SSN, whatever. *My own > > favorite way of identifying which items on one list are (or are not) tobe > > found on the other uses the MATCH function in a helper column: > > > =MATCH(RC1,'Other sheet'!C5,0) > > > This gets me a list of row numbers for the items that are on the other > > sheet, and #N/A for each item that isn't. *Usually I want to check both ways, > > but that's up to you; the point heer is that you'll put something like that > > MATCH formula up and down some column in one or both sheets, and after that > > your program can look at the results to cross-check all the items. > > > 4) After that you can...well, you can do whatever you wanted your program to > > do. *But maybe it's time to stop and let you ask more detailed questions, or > > maybe tell me I misunderstood your goal completely. > > > --- "Brian" wrote: > > > I have two workbooks that I need to compare and then copy the data that is > > > missing from the original workbook (but present in the second one) into a > > > third new workbook. To complicate matters for every comparison the filename > > > of the workbooks to be compared chages.- Skjul tekst i anførselstegn - > > - Vis tekst i anførselstegn - |
|
||
|
||||
|
Brian
Guest
Posts: n/a
|
Per,
Yes, a new entry is found if the identifier is found in one sheet but not the other. After a new identifier is found I would like to take the entire row and copy it to a third workbook. Identifiers are unique and will only ever be used once. Thanks alot, Brian "Per Jessen" wrote: > Hi Brian > > You say that column C has a unique identifier, does that mean that a > new entry is found if the identifier isn't found in both sheets, or do > we need to compare several columns once we have found a identifier > match ? > > Can the identifier be found more than once in column C ? > > Regards, > Per > > On 14 Sep., 02:33, Brian <Br...@discussions.microsoft.com> wrote: > > Thanks a lot for the quick reply Bob. > > > > It sounds like a was a bit vague in my original question. Your solution was > > helpful, but I am hoping to figure something out that is a bit more > > automated. I am trying to build a macro that can be used by anyone in my > > group so it needs to be a standalone spreadsheet. > > > > To start I've put in sFileName = Application.GetOpenFilename so they can > > then choose the 2 files ,which is working great! > > > > The files being compared are about fifty columns across, but each has a > > unique identifier in column C. Throughout the day we receive multiple of > > these files and need a quick way to find which rows are new. > > > > I was able to write a macro (which is below) that essentially compared row 1 > > in sheet 1 to row 1 in sheet 2 all the way down. This worked until there was > > one new row of data and then everything after that was considered > > "new/different" and was pulled into the output sheet. > > > > Is there anyway to write a formula that will recognize that a row exists in > > both sheets, even if the row letter numbers do not match, and therefore only > > pull out the rows that do not have a match in any other row? > > > > Dim wbkComp As Workbook > > Dim wbkWith As Workbook > > Dim wbkDiff As Workbook > > Dim shtComp As Worksheet > > Dim shtWith As Worksheet > > Dim shtDiff As Worksheet > > Dim lngCompRow As Long > > Dim lngDiffRow As Long > > Dim blnSame As Boolean > > Dim intCol As Integer > > > > Set wbkComp = Workbooks("Trade Blotter 2.xls") > > Set wbkWith = Workbooks("Trade Blotter 1.xls") > > Set wbkDiff = Workbooks.Add > > > > For Each shtComp In wbkComp.Worksheets > > Application.StatusBar = "Checking " & shtComp.Name > > Set shtWith = wbkWith.Worksheets(shtComp.Name) > > Set shtDiff = wbkDiff.Worksheets.Add > > shtDiff.Name = "Diff " & shtComp.Name > > lngCompRow = 1 > > lngDiffRow = 1 > > Do While shtComp.Cells(lngCompRow, 2) <> "" > > blnSame = True > > For intCol = 1 To 10 > > If shtComp.Cells(lngCompRow, intCol) <> > > shtWith.Cells(lngCompRow, intCol) Then > > blnSame = False > > Exit For > > End If > > Next > > If Not blnSame Then > > shtComp.Rows(lngCompRow).Copy shtDiff.Cells(lngDiffRow, 1) > > lngDiffRow = lngDiffRow + 1 > > End If > > lngCompRow = lngCompRow + 1 > > Loop > > Next > > Application.StatusBar = False > > > > Thanks a lot! > > > > Brian > > > > > > > > "Bob Bridges" wrote: > > > Well, let's work through it a piece at a time: > > > > > 1) Get the user to name one or both files; there are various > > > get-the-file-name dialogues out there, but GetOpenFilename is already built > > > into Excel. (Or so it says here; I've never tired it, but I expect it's > > > easy.) > > > > > 2) Open both workbooks, of course, along with some error checking to be sure > > > they're both there and both of the expected type. > > > > > 3) You didn't say exactly what sort of comparison will be going on here, but > > > the usual is a list in both workbooks of some item, each item uniquely > > > identified by (say) student ID, part number, VIN, SSN, whatever. My own > > > favorite way of identifying which items on one list are (or are not) to be > > > found on the other uses the MATCH function in a helper column: > > > > > =MATCH(RC1,'Other sheet'!C5,0) > > > > > This gets me a list of row numbers for the items that are on the other > > > sheet, and #N/A for each item that isn't. Usually I want to check both ways, > > > but that's up to you; the point heer is that you'll put something like that > > > MATCH formula up and down some column in one or both sheets, and after that > > > your program can look at the results to cross-check all the items. > > > > > 4) After that you can...well, you can do whatever you wanted your program to > > > do. But maybe it's time to stop and let you ask more detailed questions, or > > > maybe tell me I misunderstood your goal completely. > > > > > --- "Brian" wrote: > > > > I have two workbooks that I need to compare and then copy the data that is > > > > missing from the original workbook (but present in the second one) into a > > > > third new workbook. To complicate matters for every comparison the filename > > > > of the workbooks to be compared chages.- Skjul tekst i anførselstegn - > > > > - Vis tekst i anførselstegn - > > |
|
||
|
||||
|
Per Jessen
Guest
Posts: n/a
|
Hi Brian
This should do it (not tested): Set wbkComp = Workbooks("Trade Blotter 2.xls") Set wbkWith = Workbooks("Trade Blotter 1.xls") Set wbkDiff = Workbooks.Add For Each shtComp In wbkComp.Worksheets Application.StatusBar = "Checking " & shtComp.Name Set shtWith = wbkWith.Worksheets(shtComp.Name) Set shtDiff = wbkDiff.Worksheets.Add shtDiff.Name = "Diff " & shtComp.Name LastRow = shtComp.Range("C1").End(xlDown).Row lngDiffRow = 1 shtComp.Activate For r = 1 To LastRow Set Diff = shtWith.Columns("C").Find(what:=Cells(r, "C").Value, LookAt:=xlWhole) If Diff Is Nothing Then Rows(r).Copy Destination:=shtDiff.Cells(lngDiffRow, 1) lngDiffRow = lngDiffRow + 1 End If Next Next Application.StatusBar = False Application.ScreenUpdating = True Regards, Per On 14 Sep., 04:26, Brian <Br...@discussions.microsoft.com> wrote: > Per, > > Yes, a new entry is found if the identifier is found in one sheet but not > the other. After a new identifier is found I would like to take the entire > row and copy it to a third workbook. > > Identifiers are unique and will only ever be used once. * > > Thanks alot, > > Brian > > > > "Per Jessen" wrote: > > Hi Brian > > > You say that column C has a unique identifier, does that mean that a > > new entry is found if the identifier isn't found in both sheets, or do > > we need to compare several columns once we have found a identifier > > match ? > > > Can the identifier be found more than once in column C ? > > > Regards, > > Per > > > On 14 Sep., 02:33, Brian <Br...@discussions.microsoft.com> wrote: > > > Thanks a lot for the quick reply Bob. > > > > It sounds like a was a bit vague in my original question. Your solution was > > > helpful, but I am hoping to figure something out that is a bit more > > > automated. I am trying to build a macro that can be used by anyone inmy > > > group so it needs to be a standalone spreadsheet. > > > > To start I've put in sFileName = Application.GetOpenFilename so they can > > > then choose the 2 files ,which is working great! > > > > The files being compared are about fifty columns across, but each hasa > > > unique identifier in column C. Throughout the day we receive multipleof > > > these files and need a quick way to find which rows are new. > > > > I was able to write a macro (which is below) that essentially compared row 1 > > > in sheet 1 to row 1 in sheet 2 all the way down. This worked until there was > > > one new row of data and then everything after that was considered > > > "new/different" and was pulled into the output sheet. > > > > Is there anyway to write a formula that will recognize that a row exists in > > > both sheets, even if the row letter numbers do not match, and therefore only > > > pull out the rows that do not have a match in any other row? > > > > Dim wbkComp As Workbook > > > * * Dim wbkWith As Workbook > > > * * Dim wbkDiff As Workbook > > > * * Dim shtComp As Worksheet > > > * * Dim shtWith As Worksheet > > > * * Dim shtDiff As Worksheet > > > * * Dim lngCompRow As Long > > > * * Dim lngDiffRow As Long > > > * * Dim blnSame As Boolean > > > * * Dim intCol As Integer > > > > * * Set wbkComp = Workbooks("Trade Blotter 2.xls") > > > * * Set wbkWith = Workbooks("Trade Blotter 1.xls") > > > * * Set wbkDiff = Workbooks.Add > > > > * * For Each shtComp In wbkComp.Worksheets > > > * * * * Application.StatusBar = "Checking " & shtComp.Name > > > * * * * Set shtWith = wbkWith.Worksheets(shtComp.Name) > > > * * * * Set shtDiff = wbkDiff.Worksheets.Add > > > * * * * shtDiff.Name = "Diff " & shtComp.Name > > > * * * * lngCompRow = 1 > > > * * * * lngDiffRow = 1 > > > * * * * Do While shtComp.Cells(lngCompRow, 2) <> "" > > > * * * * * * blnSame = True > > > * * * * * * For intCol = 1 To 10 > > > * * * * * * * * If shtComp.Cells(lngCompRow, intCol) <> > > > shtWith.Cells(lngCompRow, intCol) Then > > > * * * * * * * * * * blnSame = False > > > * * * * * * * * * * Exit For > > > * * * * * * * * End If > > > * * * * * * Next > > > * * * * * * If Not blnSame Then > > > * * * * * * * * shtComp.Rows(lngCompRow).Copy shtDiff..Cells(lngDiffRow, 1) > > > * * * * * * * * lngDiffRow = lngDiffRow + 1 > > > * * * * * * End If > > > * * * * * * lngCompRow = lngCompRow + 1 > > > * * * * *Loop > > > * * Next > > > * * Application.StatusBar = False > > > > Thanks a lot! > > > > Brian > > > > "Bob Bridges" wrote: > > > > Well, let's work through it a piece at a time: > > > > > 1) Get the user to name one or both files; there are various > > > > get-the-file-name dialogues out there, but GetOpenFilename is already built > > > > into Excel. *(Or so it says here; I've never tired it, but I expect it's > > > > easy.) > > > > > 2) Open both workbooks, of course, along with some error checking to be sure > > > > they're both there and both of the expected type. > > > > > 3) You didn't say exactly what sort of comparison will be going on here, but > > > > the usual is a list in both workbooks of some item, each item uniquely > > > > identified by (say) student ID, part number, VIN, SSN, whatever. *My own > > > > favorite way of identifying which items on one list are (or are not) to be > > > > found on the other uses the MATCH function in a helper column: > > > > > =MATCH(RC1,'Other sheet'!C5,0) > > > > > This gets me a list of row numbers for the items that are on the other > > > > sheet, and #N/A for each item that isn't. *Usually I want to check both ways, > > > > but that's up to you; the point heer is that you'll put something like that > > > > MATCH formula up and down some column in one or both sheets, and after that > > > > your program can look at the results to cross-check all the items. > > > > > 4) After that you can...well, you can do whatever you wanted your program to > > > > do. *But maybe it's time to stop and let you ask more detailed questions, or > > > > maybe tell me I misunderstood your goal completely. > > > > > --- "Brian" wrote: > > > > > I have two workbooks that I need to compare and then copy the data that is > > > > > missing from the original workbook (but present in the second one) into a > > > > > third new workbook. To complicate matters for every comparison the filename > > > > > of the workbooks to be compared chages.- Skjul tekst i anførselstegn - > > > > - Vis tekst i anførselstegn -- Skjul tekst i anførselstegn - > > - Vis tekst i anførselstegn - |
|
||
|
||||
|
Brian
Guest
Posts: n/a
|
This is working perfectly. I can't thank you enough, Per!
Brian "Per Jessen" wrote: > Hi Brian > > This should do it (not tested): > > Set wbkComp = Workbooks("Trade Blotter 2.xls") > Set wbkWith = Workbooks("Trade Blotter 1.xls") > Set wbkDiff = Workbooks.Add > > > For Each shtComp In wbkComp.Worksheets > Application.StatusBar = "Checking " & shtComp.Name > Set shtWith = wbkWith.Worksheets(shtComp.Name) > Set shtDiff = wbkDiff.Worksheets.Add > shtDiff.Name = "Diff " & shtComp.Name > LastRow = shtComp.Range("C1").End(xlDown).Row > lngDiffRow = 1 > shtComp.Activate > > For r = 1 To LastRow > Set Diff = shtWith.Columns("C").Find(what:=Cells(r, > "C").Value, LookAt:=xlWhole) > If Diff Is Nothing Then > Rows(r).Copy Destination:=shtDiff.Cells(lngDiffRow, 1) > lngDiffRow = lngDiffRow + 1 > End If > Next > Next > Application.StatusBar = False > Application.ScreenUpdating = True > > Regards, > Per > > On 14 Sep., 04:26, Brian <Br...@discussions.microsoft.com> wrote: > > Per, > > > > Yes, a new entry is found if the identifier is found in one sheet but not > > the other. After a new identifier is found I would like to take the entire > > row and copy it to a third workbook. > > > > Identifiers are unique and will only ever be used once. > > > > Thanks alot, > > > > Brian > > > > > > > > "Per Jessen" wrote: > > > Hi Brian > > > > > You say that column C has a unique identifier, does that mean that a > > > new entry is found if the identifier isn't found in both sheets, or do > > > we need to compare several columns once we have found a identifier > > > match ? > > > > > Can the identifier be found more than once in column C ? > > > > > Regards, > > > Per > > > > > On 14 Sep., 02:33, Brian <Br...@discussions.microsoft.com> wrote: > > > > Thanks a lot for the quick reply Bob. > > > > > > It sounds like a was a bit vague in my original question. Your solution was > > > > helpful, but I am hoping to figure something out that is a bit more > > > > automated. I am trying to build a macro that can be used by anyone in my > > > > group so it needs to be a standalone spreadsheet. > > > > > > To start I've put in sFileName = Application.GetOpenFilename so they can > > > > then choose the 2 files ,which is working great! > > > > > > The files being compared are about fifty columns across, but each has a > > > > unique identifier in column C. Throughout the day we receive multiple of > > > > these files and need a quick way to find which rows are new. > > > > > > I was able to write a macro (which is below) that essentially compared row 1 > > > > in sheet 1 to row 1 in sheet 2 all the way down. This worked until there was > > > > one new row of data and then everything after that was considered > > > > "new/different" and was pulled into the output sheet. > > > > > > Is there anyway to write a formula that will recognize that a row exists in > > > > both sheets, even if the row letter numbers do not match, and therefore only > > > > pull out the rows that do not have a match in any other row? > > > > > > Dim wbkComp As Workbook > > > > Dim wbkWith As Workbook > > > > Dim wbkDiff As Workbook > > > > Dim shtComp As Worksheet > > > > Dim shtWith As Worksheet > > > > Dim shtDiff As Worksheet > > > > Dim lngCompRow As Long > > > > Dim lngDiffRow As Long > > > > Dim blnSame As Boolean > > > > Dim intCol As Integer > > > > > > Set wbkComp = Workbooks("Trade Blotter 2.xls") > > > > Set wbkWith = Workbooks("Trade Blotter 1.xls") > > > > Set wbkDiff = Workbooks.Add > > > > > > For Each shtComp In wbkComp.Worksheets > > > > Application.StatusBar = "Checking " & shtComp.Name > > > > Set shtWith = wbkWith.Worksheets(shtComp.Name) > > > > Set shtDiff = wbkDiff.Worksheets.Add > > > > shtDiff.Name = "Diff " & shtComp.Name > > > > lngCompRow = 1 > > > > lngDiffRow = 1 > > > > Do While shtComp.Cells(lngCompRow, 2) <> "" > > > > blnSame = True > > > > For intCol = 1 To 10 > > > > If shtComp.Cells(lngCompRow, intCol) <> > > > > shtWith.Cells(lngCompRow, intCol) Then > > > > blnSame = False > > > > Exit For > > > > End If > > > > Next > > > > If Not blnSame Then > > > > shtComp.Rows(lngCompRow).Copy shtDiff..Cells(lngDiffRow, 1) > > > > lngDiffRow = lngDiffRow + 1 > > > > End If > > > > lngCompRow = lngCompRow + 1 > > > > Loop > > > > Next > > > > Application.StatusBar = False > > > > > > Thanks a lot! > > > > > > Brian > > > > > > "Bob Bridges" wrote: > > > > > Well, let's work through it a piece at a time: > > > > > > > 1) Get the user to name one or both files; there are various > > > > > get-the-file-name dialogues out there, but GetOpenFilename is already built > > > > > into Excel. (Or so it says here; I've never tired it, but I expect it's > > > > > easy.) > > > > > > > 2) Open both workbooks, of course, along with some error checking to be sure > > > > > they're both there and both of the expected type. > > > > > > > 3) You didn't say exactly what sort of comparison will be going on here, but > > > > > the usual is a list in both workbooks of some item, each item uniquely > > > > > identified by (say) student ID, part number, VIN, SSN, whatever. My own > > > > > favorite way of identifying which items on one list are (or are not) to be > > > > > found on the other uses the MATCH function in a helper column: > > > > > > > =MATCH(RC1,'Other sheet'!C5,0) > > > > > > > This gets me a list of row numbers for the items that are on the other > > > > > sheet, and #N/A for each item that isn't. Usually I want to check both ways, > > > > > but that's up to you; the point heer is that you'll put something like that > > > > > MATCH formula up and down some column in one or both sheets, and after that > > > > > your program can look at the results to cross-check all the items. > > > > > > > 4) After that you can...well, you can do whatever you wanted your program to > > > > > do. But maybe it's time to stop and let you ask more detailed questions, or > > > > > maybe tell me I misunderstood your goal completely. > > > > > > > --- "Brian" wrote: > > > > > > I have two workbooks that I need to compare and then copy the data that is > > > > > > missing from the original workbook (but present in the second one) into a > > > > > > third new workbook. To complicate matters for every comparison the filename > > > > > > of the workbooks to be compared chages.- Skjul tekst i anførselstegn - > > > > > > - Vis tekst i anførselstegn -- Skjul tekst i anførselstegn - > > > > - Vis tekst i anførselstegn - > > |
|
||
|
||||
|
|
|
| |
![]() |
| Thread Tools | |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Copying a formula from multiple workbooks down rows and across col | Rookie | Microsoft Excel Programming | 3 | 12th Jan 2010 05:57 PM |
| comparing rows of two workbooks | nasirmuneer@gmail.com | Microsoft Excel Programming | 2 | 8th Jul 2008 04:18 PM |
| comparing lists in 2 workbooks and de-duplicating | =?Utf-8?B?QWxhbiBN?= | Microsoft Excel Programming | 1 | 7th Mar 2007 08:22 PM |
| Comparing data between sheets, and copying rows with data | =?Utf-8?B?Rmxlb25l?= | Microsoft Excel Programming | 1 | 2nd Jun 2006 06:54 PM |
| Comparing Names In 2 Lists To Find Missing Ones | David Gibson | Microsoft Access Queries | 1 | 1st Dec 2003 11:28 AM |
Powered by vBulletin®. Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2010, Crawlability, Inc. |




