Reputation: 11
Whilst trying to populate two seperate fields, i'm receiving a runtime 13 error
the code to add the text to the fields is
Private Sub cmdAddMDS_Click()
SetText GetMDS(currentMDS, cboxMDS.Value)
SetCat catMDS(currentMDS, cboxMDS.Value) <-- This creates the runtime error
End Sub
The Subs to set the value to be added are near identical, just different sub name and offset
Function GetMDS(mdsName As Worksheet, templateName As String) As String
Dim Lrow As Long, rng As Range
On Error Resume Next
Lrow = mdsName.Range("A" & Rows.Count).End(xlUp).row
With mdsName.Range("A2:A" & Lrow)
Set rng = .Find(templateName, LookIn:=xlValues)
If Not rng Is Nothing Then
GetMDS = rng.Offset(, 1).Value
End If
End With
End Function
----------------------------------------------------------
Function catMDS(mdsName As Worksheet, templateName As String) As String
Dim Lrow As Long, rng As Range
On Error Resume Next
Lrow = mdsName.Range("A" & Rows.Count).End(xlUp).row
With mdsName.Range("A2:A" & Lrow)
Set rng = .Find(templateName, LookIn:=xlValues)
If Not rng Is Nothing Then
catMDS = rng.Offset(, 3).Value
End If
End With
End Function
Does anyone have any Insight to what may be causing this error?
Upvotes: 1
Views: 477
Reputation: 11
i figured out the answer, i was using the same name for two different parameters which was causing a conflict
Upvotes: 0
Reputation: 51998
In the line
SetCat catMDS(currentMDS, cboxMDS.Value)
two things can trigger a type mismatch error:
1) There is a problem passing the parameters to the function
catMDS
2) There is a problem passing the returned string to
SetCat
Since the values passed to catMDS
appear to be the same as the values passed to GetMDS
and those two functions have the same type, explanation 1) is unlikely. BUT -- all bets are off if SetText
modified one of those values.
Thus -- 2) is likely to be the case. Since you haven't revealed what SetCat
does, we have no way of knowing why it would cause an error. You might want to edit your question to include that sub.
For debugging purposes, you could modify your code as follows:
Private Sub cmdAddMDS_Click()
Dim s As String
SetText GetMDS(currentMDS, cboxMDS.Value)
s = catMDS(currentMDS, cboxMDS.Value)
SetCat s
End Sub
This will separate the function call from the sub call. One of the last two lines should throw an error. Which line throws the error will allow you to focus your debugging efforts.
Upvotes: 1