+ Reply to Thread
Results 1 to 5 of 5

Validate Data between two workbooks

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-10-2014
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2205 Build 16.0.15225.20368) 64-bit
    Posts
    100

    Validate Data between two workbooks

    Hello,

    I am looking to see if there is a way in which I can validate that the totals from my one workbook (Lakers Stats By Season) to make sure that they match with a player's totals in the workbook 1989-90 Los Angeles Lakers. The worksheet to follow within the 1989-90 Los Angeles Lakers workbook is named 1989-90 Stats. I have attached both workbooks and I have all of the headers that would need to be validated from the column that has G as the header all the way to PTS based off the player name.

    I will be wanting to do this for other workbooks that are not attached and validating the totals data using the workbook Lakers Stats By Season, I have named each sheet after the workbook that I will be working with.

    Let me know if this is possible and Thank You in advance for your help.
    Attached Files Attached Files

  2. #2
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Validate Data between two workbooks

    Hi kingsdime29x- Here's a macro to handle your validation. It opens your 'XXX...Lakers' WBs one at a time, runs a comparison, and closes them. I've included instructions in the attached workbook. Let me know if you have any problems. -Lee
    ps. If this does the trick, please mark the thread as SOLVED (Thread Tools, up top)... and perhaps click the Add Reputation star at the bottom of this post. Thanks!

    for the browsers:
    Sub CompareStats()
    
        '''''''''''''''''''    LLN 2017-04-21    '''''''''''''''''''''''
        
        Dim rw As Long, indx As Long, cnt As Long, errRow As Long, errCnt As Long
        Dim player As String, statsLAL As Range, statsBS As Range, found As Range
        Dim folderpath As String, WBLAL As String, WS As Worksheet
        
        Application.ScreenUpdating = False
        ThisWorkbook.Activate
        folderpath = Application.ThisWorkbook.Path & "\"
    
        For cnt = 1 To ThisWorkbook.Worksheets.Count
            Set WS = Worksheets(cnt)
            WBLAL = WS.Name & ".xlsx"
            Workbooks.Open folderpath & WBLAL
            WS.Activate
            With Workbooks(WBLAL).Worksheets(Left(WS.Name, 7) & " Stats") '1989-90 Stats
    
                errRow = Cells(2, 2).End(xlDown).Row + 2
                Range("A1:P1").Copy Destination:=Cells(errRow, 1)
    
                For rw = 2 To Cells(2, 2).End(xlDown).Row
                    player = Cells(rw, 2).Value
                    Set found = .Range("B:B").Find(player)
    
                    If found Is Nothing Then
                        errRow = errRow + 1
                        errCnt = errCnt + 1
                        Cells(errRow, 2) = player & " NOT FOUND"
    
                    Else
                        Set statsBS = Range("C1:P1").Offset(rw - 1)
                        Set statsLAL = .Range("D1:Q1").Offset(found.Offset(, 1).End(xlDown).Row - 1)
    
                        For indx = 1 To 14
    
                            If statsBS.Cells(1, indx).Value <> statsLAL.Cells(1, indx).Value Then
                                errRow = errRow + 1
                                errCnt = errCnt + 1
                                Cells(errRow, 2).Value = player
                                Cells(errRow, indx + 2).Value = statsLAL.Cells(1, indx).Value
    
                            End If
                        Next
                    End If
                Next
            End With
            Workbooks(WBLAL).Close SaveChanges:=False
        Next
        
        Application.ScreenUpdating = True
        Beep
        MsgBox "All done. " & errCnt & " errors were found.", , "CompareStats macro"
    
    End Sub
    Attached Files Attached Files

  3. #3
    Forum Contributor
    Join Date
    12-10-2014
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2205 Build 16.0.15225.20368) 64-bit
    Posts
    100

    Re: Validate Data between two workbooks

    This is perfect! Thank you so much for your help.

  4. #4
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Validate Data between two workbooks

    My pleasure. Did you turn up many errors? If so, I could easily adjust the macro to change the 'By Season' data to match the Season Books.

  5. #5
    Forum Contributor
    Join Date
    12-10-2014
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2205 Build 16.0.15225.20368) 64-bit
    Posts
    100

    Re: Validate Data between two workbooks

    Very few errors occurred and is working exactly as I would like. Thank you again for you help with this.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. compare and validate data in two different workbooks
    By Andyb800 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-18-2016, 10:38 PM
  2. VBA code to validate formula cells and do condition check in closed workbooks
    By johnmacpro in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-11-2016, 11:52 PM
  3. compare and validate data between two workbooks
    By bmbalamurali in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-05-2015, 06:50 AM
  4. [SOLVED] How do I validate data and then summarize corresponding amounts that matches the data?
    By Chase1026 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-18-2014, 04:21 PM
  5. How to validate whenever new data is entered
    By jrexcel1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-13-2012, 03:43 PM
  6. Validate two fields when one field you need a formula to validate
    By cmwilbur in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-29-2010, 11:32 AM
  7. Validate data
    By JT in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-27-2005, 05:06 PM

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.6.0 RC 1