Type Mismatch Error when migrating data from oen workbook to another

Needing help in resolving a "Type Mismatch" Error.

When I execute the macro to migrate "OLD DATA" to "NEW DAT, I'm getting the error.  Please see atachments.C--Users-lfreund-Downloads-OLD-DATA.xlsx
C--Users-lfreund-Downloads-NEW-DATA.xlsm
LUIS FREUNDAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
This should do the job.

Sub getMatchingDataFromOldFile()
Dim wbNew As Workbook, wbOld As Workbook
Dim wsNew As Worksheet, wsOld As Worksheet
Dim sFile, r
Dim slr As Long, i As Long, lr As Long
Dim arrNew, arrOld, LookupArr, oldIR()

Application.ScreenUpdating = False

Set wbNew = ThisWorkbook

sFile = Application.GetOpenFilename(FileFilter:="Excel Workbooks ,*.xls*", Title:="Open Old Data File", MultiSelect:=False)
If sFile = False Then
    MsgBox "You didn't select the Old Data File", vbExclamation, "Action Cancelled By User!"
    Exit Sub
End If
Set wbOld = Workbooks.Open(sFile)

For Each wsNew In wbNew.Sheets
    slr = wsNew.Cells(Rows.Count, 1).End(xlUp).Row
    arrNew = wsNew.Range("A2:A" & slr).Value
    ReDim oldIR(1 To UBound(arrNew, 1), 1 To 10)
    Set wsOld = getOldSheet(wsNew, wbOld)
    If Not wsOld Is Nothing Then
        lr = wsOld.Cells(Rows.Count, 1).End(xlUp).Row
        arrOld = wsOld.Range("A1").CurrentRegion.Value
        LookupArr = wsOld.Range("A2:A" & lr).Value
        For i = 1 To UBound(arrNew, 1)
            r = Application.Match(arrNew(i, 1), LookupArr, 0)
            If Not IsError(r) Then
                oldIR(i, 1) = arrOld(i + 1, 9)
                oldIR(i, 2) = arrOld(i + 1, 10)
                oldIR(i, 3) = arrOld(i + 1, 11)
                oldIR(i, 4) = arrOld(i + 1, 12)
                oldIR(i, 5) = arrOld(i + 1, 13)
                oldIR(i, 6) = arrOld(i + 1, 14)
                oldIR(i, 7) = arrOld(i + 1, 15)
                oldIR(i, 8) = arrOld(i + 1, 16)
                oldIR(i, 9) = arrOld(i + 1, 17)
                oldIR(i, 10) = arrOld(i + 1, 18)
            End If
        Next i
        wsNew.Range("I2").Resize(UBound(oldIR), 10).Value = oldIR
        wsNew.Range("I2").Resize(UBound(oldIR), 10).WrapText = False
    End If
Next wsNew
wbOld.Close False
Application.ScreenUpdating = True
MsgBox "Data has been copied from Old Data File successfully.", vbInformation, "Done!"
End Sub


Function getOldSheet(ByVal wsN As Worksheet, ByVal wb As Workbook) As Worksheet
Dim ws As Worksheet
For Each ws In wb.Sheets
    If ws.Name = wsN.Name Then
        Set getOldSheet = ws
        Exit For
    End If
Next ws
End Function

Open in new window

C-NEW-DATA-v2.xlsm
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Roy CoxGroup Finance ManagerCommented:
It seems to run OK to me, no error message just the success message.

I've tried adding an error message but no error occurs

Option Explicit

Sub getMatchingDataFromOldFile()
    Dim wbNew As Workbook, wbOld As Workbook
    Dim wsNew As Worksheet, wsOld As Worksheet
    Dim sFile, r
    Dim slr As Long, i As Long
    Dim arrNew, arrOld, oldIR()

    Application.ScreenUpdating = False

    Set wbNew = ThisWorkbook
    On Error GoTo exit_Proc
    sFile = Application.GetOpenFilename(FileFilter:="Excel Workbooks ,*.xls*", Title:="Open Old Data File", MultiSelect:=False)
    If sFile = False Then
        MsgBox "You didn't select the Old Data File", vbExclamation, "Action Cancelled By User!"
        Exit Sub
    End If
    Set wbOld = Workbooks.Open(sFile)

    For Each wsNew In wbNew.Sheets
        slr = wsNew.Cells(Rows.Count, 1).End(xlUp).Row
        arrNew = wsNew.Range("A2:A" & slr).Value
        ReDim oldIR(1 To UBound(arrNew, 1), 1 To 10)
        Set wsOld = getOldSheet(wsNew, wbOld)
        If Not wsOld Is Nothing Then
            arrOld = wsOld.Range("A1").CurrentRegion.Value
            For i = 1 To UBound(arrNew, 1)
                r = Application.Match(arrNew(i, 1), Application.Index(arrOld, , 1), 0)
                If Not IsError(r) Then
                    oldIR(i, 1) = arrOld(i + 1, 9)
                    oldIR(i, 2) = arrOld(i + 1, 10)
                    oldIR(i, 3) = arrOld(i + 1, 11)
                    oldIR(i, 4) = arrOld(i + 1, 12)
                    oldIR(i, 5) = arrOld(i + 1, 13)
                    oldIR(i, 6) = arrOld(i + 1, 14)
                    oldIR(i, 7) = arrOld(i + 1, 15)
                    oldIR(i, 8) = arrOld(i + 1, 16)
                    oldIR(i, 9) = arrOld(i + 1, 17)
                    oldIR(i, 10) = arrOld(i + 1, 18)
                End If
            Next i
            wsNew.Range("I2").Resize(UBound(oldIR), 10).Value = oldIR
            wsNew.Range("I2").Resize(UBound(oldIR), 10).WrapText = False
        End If
    Next wsNew

    wbOld.Close False
    MsgBox "Data has been copied from Old Data File successfully.", vbInformation, "Done!"
    Exit Sub
exit_Proc:
    Application.ScreenUpdating = True
    MsgBox "An error occurred"
End Sub

Open in new window

0
LUIS FREUNDAuthor Commented:
AWESOME!!!  Thank you very much!
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome Luis!
0
LUIS FREUNDAuthor Commented:
Neeraj,

Good day.  I just discovered that the data does not match up towards the bottom of the list when there is less rows of data.  For example...I have 10 less rows of data so towards the bottom of the list it's populating from the original as if there is the same amount of rows.  

So at the bottom it's not matching up...the top is perfect.  Should I re-open the question?  Many Thanks!
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Sure. But don't forget to upload the sample workbook in question and highlight the incorrect output.
0
LUIS FREUNDAuthor Commented:
Thanks Neeraj,  I've re-open the question and included the files.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.