In my code I keep having the error "Runtime error 13 - type mismatch" When I put the lines in comment that get the value from the Cell to put in the integer (qtyCode = Cells(x, "L").Value) , this disappears. But I can't seem to find out why it's type mismatch.
Column L is set as number in my excel file.
Sub counting()
Dim code As String
Dim lookup As String
Dim qtyCode As Integer
Dim qtyLookup As Integer
Dim numRows As Integer
numRows = Range("AM2", Range("AM2").End(xlDown)).Rows.Count
For x = 1 To numRows
code = Cells(x, "AM").Text
qtyCode = Cells(x, "L").Value 'error here
For y = 1 To numRows
lookup = Cells(y, "AM").Text
If (code = lookup) Then
qtyLookup = CInt(Cells(y, "L").Text) 'error here
qtyCode = qtyCode + qtyLookup
End If
ActiveCell.Offset(1, 0).Select
Next
Cells(x, "AN").Value = qtyCode
ActiveCell.Offset(1, 0).Select
Next
End Sub
I assume the solution will be easy and I'm overlooking something most likely..
Thanks in advance,
David
This is the code, there is still something wrong with the value output, but no more errors so this question is solved :)
Sub counting()
Dim code As String
Dim lookup As String
Dim a As Long
Dim b As Long
Dim c As Long
Dim numRows As Integer
numRows = Range("AM2", Range("AM2").End(xlDown)).Rows.Count
For x = 2 To numRows
code = Cells(x, "AM").Text
a = CLng(Cells(x, "L").Value)
For y = 2 To numRows
lookup = Cells(y, "AM").Text
If (code = lookup) Then
b = CLng(Cells(y, "L").Value)
c = a + b
End If
Next
Cells(x, "AN").Value = c
Next
End Sub