• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Comparing two spreadsheets for differences

Sorry it's taken me a few days to respond to this but I have gotten very busy at work. I finally ran these in my roster files and, when I run the UpdateLinked module in the "obsl_rosters.xlsx" file, I get this error:


Run-time error '9': Subscript Out of Range


And when I try to debug it, it's this line that seems to be the problem but I can't figure it out:


Set rngTarget = Workbooks(ksWB).Worksheets(ksWS).Range(ksRng)


Any thoughts?
 
Hi, sborah99!


Checking my files I noticed that in the UpdateLinked procedure in OBSL workbook I made a mistake inverting the source and target ranges, that's to say, ML was being updated according to OBSL, the opposite as you required.


I did this:


a) updated the earlier posted code from:

-----

[pre]
Code:
Set rngSource = ThisWorkbook.Worksheets(ksWS).Range(ksRng)
Set rngSourceUpdate = ThisWorkbook.Worksheets(ksWS).Range(ksRngU)
Set rngTarget = Workbooks(ksWB).Worksheets(ksWS).Range(ksRng)
Set rngTargetUpdate = Workbooks(ksWB).Worksheets(ksWS).Range(ksRngU)
-----

to:

-----

Set rngSource = Workbooks(ksWB).Worksheets(ksWS).Range(ksRng)
Set rngSourceUpdate = Workbooks(ksWB).Worksheets(ksWS).Range(ksRngU)
Set rngTarget = ThisWorkbook.Worksheets(ksWS).Range(ksRng)
Set rngTargetUpdate = ThisWorkbook.Worksheets(ksWS).Range(ksRngU)
[/pre]
-----


b) uploaded the updated files to same previous links, so download them again please


Now, regarding your question, despite this reversal you shouldn't have got a runtime error unless the worksheets have different names in both files. If so, please update the code and run it again; if not, well, you have another issue, maybe ranged names wrongly defined or something related to workbooks' structure.


Please check it and post how did you went on.


Regards!
 
Okay, I changed this part of the code:


Const ksWB = "ml_rosters.xlsx"

Const ksWS = "Sheet1"

Const ksRng = "DataTable"

Const ksRngU = "DataUpdateTable"

Const kiColumnExists = 148

Const kiColumnFullName = 150

' declarations

Dim rngSource As Range, rngSourceUpdate As Range

Dim rngTarget As Range, rngTargetUpdate As Range

Dim I As Long, J As Integer, K As Long, L As Long


However, I think the "Dim I. . ." parts need to be a different range but I'm unsure how to go about that? I am trying to use these on my original files so I know the ranges need to be changed to the range of cells in those files. Can you take me step-by-step through that? Thanks.
 
Hi, sborah99!


About Consts:


Const ksWB: if it's not in the default Excel path for opening files, it must have the full path for ML workbook

Const ksWS: must be the same sheet name in both workbooks (if need different names it's easy, duplicate constant with other name, set proper values, and change it at Set instructions

Const ksRng and ksRngU: its values should exist as named ranges in both workbooks ML & OBSL


About Dims: nothing needs to be changed, if something's wrong it's between the named range references in the workbooks (Formula tab, Names group, Names Manager icon) and the Const values in the procedure UpdateLink.


If the actual files posted earlier are the real files for the time being, just advise and I'll verify or correct them (code, modules, ranges, etc.).


Regards!
 
Hi, sborah99!


A few questions:

a) These two files are static or you'll be downloading (ergo updating) them frequently?

b) Should you want to keep the first 33 lines? Would they change in the future?

c) The name of the sheets on each workbook are different, should you keep them?


Regards!
 
Hi, sborah99!


A new issue has arised, there are duplicate players in obsl file, e.g.:

Alvarez Luis (1 in ml and 2 in obsl).


This changes the matching criteria used. Next week I'll be reading this topic again.


Regards!
 
a) The two files are static and will only be uploaded once or twice.

b) Yes I need to keep the first 33 lines. I can copy them from another file and re-insert them into the updated files

c) The names of the workbook sheets don't matter. I usually don't name those.


With Luis Alvarez and other duplicate players who show up once in ML and twice in OBSL, the non-associated player in OBSL (the one without a team) will be deleted.


Thanks.
 
Hi, sborah99!

While updating the procedures to meet your actual data, a new issue arised: Ciriaco Juan, twice in ML file, with Grand Junction Rockies and Fresno Grizzlies, and now what, which is the criteria?

It's like the children's tale, a neverending story.

Regards!
 
According to this link:


http://www.baseball-reference.com/pl/player_search.cgi?search=juan+ciriaco


there are two players named Juan Ciriaco who play major league baseball. So you can keep them both. Thanks for checking. In fact, if any players with the same name appear in the ml_rosters file, just let them stay there and I'll take care of them. Thanks again.
 
Hi, sborah99!


While I figure how to implement those changes, I still wonder why there's no better (i.e., unique, unambiguous) way to identifying each player, so... would you mind posting the original sources from where the actual files can be downloaded and the procedure (filter, selection, ...) used to create those files?


I think they might be downloaded by team, or something else. I only want to check the source, the available options and see if there's a workaround for identifying players.


Thank you.


Regards!
 
The problem with that request is that those files are produced by a baseball simulation game. The ml_rosters are from the updated version of the game while the obsl_rosters are from the last year's version of the game. So, essentially, those are the original versions of the rosters.
 
Hi, sborah99!


Thanks for the information, I arrived to a similar conclusion when I find out what OBSL meant.


Rebooting.


Give a look at these files:

https://dl.dropboxusercontent.com/u/60558749/Comparing%20two%20spreadsheets%20for%20differences%20-%20ML%20Rosters%20%28for%20sborah99%20at%20chandoo.org%29.xlsm

https://dl.dropboxusercontent.com/u/60558749/Comparing%20two%20spreadsheets%20for%20differences%20-%20OBSL%20Rosters%20%28for%20sborah99%20at%20chandoo.org%29.xlsm


In both:

a) There're defined 2 dynamic named ranges:


"DataTable" as: =DESREF(INDIRECTO(DIRECCION(COINCIDIR("//Player ID";ml_rosters!$A:$A;0)+2;1;1;1;"ml_rosters"));;;CONTARA(ml_rosters!$A:$A)-CONTAR.SI(ml_rosters!$A:$A;">=//");CONTARA(INDIRECTO("ml_rosters!$"&COINCIDIR("//Player ID";ml_rosters!$A:$A;0)&":$"&COINCIDIR("//Player ID";ml_rosters!$A:$A;0)))) -----> in english: =OFFSET(INDIRECT(ADDRESS(MATCH("//Player ID",ml_rosters!$A:$A,0)+2,1,1,1,"ml_rosters")),,,COUNTA(ml_rosters!$A:$A)-COUNTIF(ml_rosters!$A:$A,">=//"),COUNTA(INDIRECT("ml_rosters!$"&MATCH("//Player ID",ml_rosters!$A:$A,0)&":$"&MATCH("//Player ID",ml_rosters!$A:$A,0))))


"DataUpdateTable" as: =DESREF(DataTable;0;25;56) -----> in english: =OFFSEF(DataTable,0,25,,56)


The changes in the now weird range definitions are due to the first and last lines like "//..." that altered the normal and usual worksheet like database structures.


b) In worksheet Sheet1 there's a procedure SortLinked in the VBA section:

-----

[pre]
Code:
Option Explicit

Sub SortLinked()
' constants
Const ksRng = "DataTable"
' declarations
Dim rng As Range
' start
Set rng = Range(ksRng)
Application.Calculation = xlCalculationManual
' process
With ActiveSheet.Sort
With .SortFields
.Clear
.Add Key:=Range("ER:ER"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
.Add Key:=Range("EU:EU"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.Add Key:=Range("ET:ET"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.Add Key:=Range("C:C"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
End With
.SetRange rng
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
' end
Application.Calculation = xlCalculationAutomatic
Set rng = Nothing
Beep
End Sub
[/pre]
-----


c) There are 5 new columns ER:EV & ES:

ER1: title

ER2: Z (greater than below values for sorting descending because of damned row 2)

ER3 & down: =SI(ES3=0;"N";"Y") -----> in english: =IF(ES3=0,"N","Y")

ES1: title

ES3 & down: =SI.ERROR(COINCIDIR(A3;'[XXX.xlsm]Sheet1'!$A:$A;0);0) -----> in english: =IFERROR(MATCH(A3,'[XXX.xlsm]Sheet1'!$A:$A,0),0) (where XXX is the name of the other file)

ET1: title

ET3 & down: =E3&"_"&F3&"_"&K3&"_"&J3&"_"&I3&"_"&L3&"_"&N3

EU1: title

EU2: 0 (lesser than 1, for sorting ascending)

EU3 & down: =MIN(CONTAR.SI(ET$1:ET3;ET3);2) -----> in english: =MIN(COUNTIF(ET$1:ET3,ET3),2)

EV1: title

EV3 & down: "Y" if update, "" if not

In OBSL file (target) there's a module with a procedure UpdateLinked in the VBA section:

----- />
[pre]
Code:
Option Explicit

Sub UpdateLinked()
' constants
Const ksWB = "Comparing two spreadsheets for differences - ML Rosters (for sborah99 at chandoo.org).xlsm"
Const ksWSS = "ml_rosters"
Const ksWST = "obsl_rosters"
Const ksRng = "DataTable"
Const ksRngU = "DataUpdateTable"
Const kiColumnExists = 148
Const kiColumnFullID = 150
Const kiColumn1stOccurrence = 151
Const kiColumnUpdated = 152
Const ksY = "Y"
' declarations
Dim rngSource As Range, rngSourceUpdate As Range
Dim rngTarget As Range, rngTargetUpdate As Range
Dim I As Long, J As Integer, K As Long, L As Long
' start
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With
Set rngSource = Workbooks(ksWB).Worksheets(ksWSS).Range(ksRng)
Set rngSourceUpdate = Workbooks(ksWB).Worksheets(ksWSS).Range(ksRngU)
Set rngTarget = ThisWorkbook.Worksheets(ksWST).Range(ksRng)
Set rngTargetUpdate = ThisWorkbook.Worksheets(ksWST).Range(ksRngU)
rngSource.Columns(kiColumnUpdated).Cells.ClearContents
rngTarget.Columns(kiColumnUpdated).Cells.ClearContents
' process
K = 0
L = 0
For I = 1 To rngTarget.Rows.Count
If rngTarget.Cells(I, kiColumnExists).Value = "Y" And _
rngTarget.Cells(I, kiColumn1stOccurrence).Value = 1 Then
If LCase(rngSource.Cells(I, kiColumnFullID).Value) = _
LCase(rngTarget.Cells(I, kiColumnFullID).Value) Then
rngSource.Cells(I, kiColumnUpdated) = ksY
rngTarget.Cells(I, kiColumnUpdated) = ksY
For J = 1 To rngTargetUpdate.Columns.Count
rngTargetUpdate.Cells(I, J).Value = rngSourceUpdate.Cells(I, J).Value
Next J
K = K + 1
Else
L = L + 1
End If
End If
Next I
MsgBox "Matching records updated: " & K & vbCrLf & _
"Matching records not updated: " & L, _
vbApplicationModal + vbInformation, "Summary"
' end
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
Set rngTargetUpdate = Nothing
Set rngTarget = Nothing
Set rngSourceUpdate = Nothing
Set rngSource = Nothing
Beep
End Sub
[/pre]

-----


Only once steps:

1) update your workbooks as described in a), b) & c)

2) define the named ranges in them as specified


Each time steps:

1) in both files run the procedure SortLinked

2) in target (OBSL) file run the procedure UpdateLinked


Just advise if any issue.


Regards!


PS: Remember that these files have crossed links, so if renaming happens you'd have to edit data links too.


PS2: I'm gonna take vacations of baseball (specially ML & OBSL) for a few, long, days. Good luck!
 
Thanks for your help, SirJB7! Those are pretty close to what I was looking for. Enjoy your vacations, you earned them!
 
Hi, sborah99!

My "vacations" were intended to be from baseball (i.e., this ML & OBSL workbooks) if everything works fine for you now, as I guess and hope.

You say "pretty close"... hmmm... why not "fully close", what's misssing or not working as required?

Regards!
 
Everything is pretty much good, now. There are some duplicate players who aren't included in the 5,000+ you listed in both worksheets, but I can take care of those, no problem. Thanks again for all your help, SirJB7!
 
Hi, sborah99!


Glad to help you and come back whenever needed or wanted.


Regarding the non matched players I think you've already noticed it but just in case: the match is made thru the column ET column composed by the concatenation of:

E: Surname

F: Name

K: Year of birth

J: Month of birth

I: Day of birth

L: Country of birth (code)

N: City of birth (code)


So if you update this values properly for the previously non-matched players, you could then run again the process until no unmatched results.


Regards!
 
Hi again, I keep getting an error trying to use these macros with two new files.

Runtime error 9:
Subscript out of range

I have changed this data to reflect the two new files in the macro:

Const ksWB = "updated_rosters.csv"
Const ksWSS = "updated_rosters"
Const ksWST = "obsl_rosters"

But I keep getting that error when I run all the macros. Here are the links to the two new files. Can anyone show me what I'm doing wrong?

https://www.dropbox.com/s/xdpk0bndandt5r9/updated_rosters.csv

https://www.dropbox.com/s/8arhr605w4y40ox/obsl_rosters.csv

Thanks.

Stacy
 
Hi Stacy ,

First , I assume that your file does not contain what you have posted !

It should actually be :

Const ksWB = "updated_rosters.csv"
Const ksWSS = "updated_rosters"
Const ksWST = "obsl_rosters"

These errors have come in as a result of this forum moving from an earlier platform to the new platform.

If there are any more of these , they will all need to be corrected.

Narayan
 
Correct. The two files I posted do not contain those macros. I opened up the original files with the macros and updated them then copied and pasted them in the new files. But since they did not work, I too them out of the new files.

Thanks.
 
Hi Stacy ,

Are you expecting any more help ? If so , please post all relevant files ; the two files you have uploaded are csv files ; what is to be done with these ?

Narayan
 
yes, I need more help, please. I am trying to compare the new files to each other, line up the duplicates in each, and sort out the non-duplicates below the duplicates in each file. The macros posted earlier should have helped but I cannot get them to work in the new files. How should I utilize them? Thanks.
 
Hi Stacy ,

Can you post the Excel workbook ? I am not the author of the macros ; if you want me to help , please post the workbook , and check back tomorrow , since going through the macros and the data will take time.

Otherwise , you can wait for the author to respond.

Narayan
 
Back
Top