Initially in my main code section I had an ugly if statement - though ugly it would run. I decided to make it a function that I would call, this caused me to get an error "Compile error: ByRef argument type mismatch". My assumption is that the function needs to be referenced properly, though I've been reading the documentation and can't see why >.<
Declaring ShiftValue variable:
Dim ShiftValue As String
ShiftValue = LCase(Sheets("Raw_Rota").Cells(Counter, "C").Value)
The function contents and declaration:
Function ShiftCompare(ByRef ShiftValue As String)
If StrComp(ShiftValue, "am", vbTextCompare) = 0 Then
Call IncAMs(AMs) 'this function increments the variable by 1.
Call Inc(Counter)
ElseIf StrComp(ShiftValue, "pm", vbTextCompare) = 0 Then
Call IncPMs(PMs)
Call Inc(Counter)
ElseIf StrComp(ShiftValue, "days", vbTextCompare) = 0 Then
Call IncDays(Days)
Call Inc(Counter)
ElseIf StrComp(ShiftValue, "leave", vbTextCompare) = 0 Then
Call IncLeave(Leave)
Call Inc(Counter)
Else 'If the string doesn't compare to the above values tally it as unknown
Call IncUnknown(Unknown)
Call Inc(Counter)
End If
End Function
Update:
My function call is in the Else part of an If section like so:
If X
"'Do stuff..."
Else
Call ShiftCompare(ShiftValue)
EndIf
The error is raised on the Function line:
Function ShiftCompare(ByVal ShiftValue As String)
The value in whatever cell being referenced is either empty or a string.
The value of the parameter when you are calling the function is not a string. Check the value of
ShiftValue
and try again. If you want to make sure it is a string, pass it like thisCall ShiftCompare("MyStringValue")
The idea of the Function is that it is good that it returns a value. Yours does not return. Change
Function
toSub
.