Runtime Error 13 Type mismatch- What am I dong wrong?

ghostbroker2

Board Regular
Joined
Feb 13, 2017
Messages
58
here is the dropbox link for the 2 spreadsheets:
Dropbox - Rewinder Tracking

Debug highlights Line 17; .Value = .Value + Range("F5").Value
Here is the VBA:

Sub macSubmitProduction()
Dim W As Workbook
Dim C As Range
Dim lngR As Long

Set W = Application.Workbooks.Open("\\RWCAD\Rewinding Schedule\PRODUCTION REPORTS\REWINDER TRACKING\Rewinder Tracking TEST.xlsx")
Set C = W.Sheets(1).Cells.Find(Range("K1").Value)

If C Is Nothing Then
MsgBox Range("K1").Value & " Was Not Found!"
Exit Sub
End If

lngR = C.Row

With W.Sheets(1).Cells(lngR, "G")
.Value = .Value + Range("F5").Value
End With
With W.Sheets(1).Cells(lngR, "E")
.Value = .Value + Range("F3").Value
End With
With W.Sheets(1).Cells(lngR, "D")
.Value = .Value + Range("T1").Value
End With

W.Close True

Call macClean

End Sub

I'm still new to VBA, so any direction is appreciated.

Thank you
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Your range references in red font are defaulting to the host workbook active sheet. If that is not what you intended, then it is probably where the error is being generated due to those cells containing a different data type than the W.Sheets(1) cells.
Code:
With W.Sheets(1).Cells(lngR, "G")
 .Value = .Value + [COLOR=#B22222]Range("F5").[/COLOR]Value
 End With
 With W.Sheets(1).Cells(lngR, "E")
 .Value = .Value +[COLOR=#B22222] Range("F3").[/COLOR]Value
 End With
 With W.Sheets(1).Cells(lngR, "D")
 .Value = .Value + [COLOR=#B22222]Range("T1").[/COLOR]Va[COLOR=#B22222][/COLOR]lue
 End With
If you want them to refer to the W.Sheets(1) cells, put a period in front of them.
 
Upvote 0
When you debug, what line does the error happen on?

You don't need three With/End With's.

Code:
    With W.Sheets(1)
               .Cells(lngR, "G") .Value = .Value + Range("F5").Value
               .Cells(lngR, "E") .Value = .Value + Range("F3").Value
               .Cells(lngR, "D").Value = .Value + Range("T1").Value

    End With
 
Upvote 0
It is risky to refer to the wrong workbook without the workbookname.
Maybe better to define searchrange.

Code:
Sub macSubmitProduction()
    Dim W, wbSource As Workbook
    Dim C As Range
    Dim lngR As Long
    
    Set wbSource = ActiveWorkbook
    Set W = Application.Workbooks.Open("D:\users\martin\Downloads\Rewinder Tracking TEST.xlsx")
    Set C = W.Sheets(1).[COLOR=#ff0000]Range("B1:B13")[/COLOR].Find(wbSource.Sheets(1).Range("K1").Value)
    
    If C Is Nothing Then
        MsgBox wbSource.Sheets(1).Range("K1").Value & " Was Not Found!"
        Exit Sub
    End If
    
    lngR = C.Row
    
    With W.Sheets(1).Cells(lngR, "G")
        .Value = .Value + [COLOR=#ff0000]wbSource.Sheets(1)[/COLOR].Range("F5").Value
    End With
    With W.Sheets(1).Cells(lngR, "E")
        .Value = .Value + wbSource.Sheets(1).Range("F3").Value
    End With
    With W.Sheets(1).Cells(lngR, "D")
        .Value = .Value + wbSource.Sheets(1).Range("T1").Value
    End With
    
    W.Close True
    
    Call macClean
    
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top