ByRef argument type mismatch error

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am receiving a 'ByRef argument type mismatch' error with the highlighted code below...

Rich (BB code):
Dim wstime1, wstime2, wstime3, wstime4, wstime5 As String
Dim lNumber1, lNumber2, lNumber3, lNumber4, lNumber5 As Long

wstime1 = Application.WorksheetFunction.VLookup(lrid, rvl5, 43, False)
wstime2 = Application.WorksheetFunction.VLookup(lrid, rvl5, 46, False)
lNumber1 = GetFirstNumeric(wstime1)
lNumber2 = GetFirstNumeric(wstime2)

In my testing wstime1 should equal "<2:30 PM" (can't check as the code errors before i can step through)

'GetFirstNumeric' is a function ...
Rich (BB code):
Function GetFirstNumeric(s As String) As Long
    Dim u As Long
    For u = 1 To Len(s)
        If Mid(s, u, 1) Like "#" Then
            GetFirstNumeric = u
            Exit For
        End If
    Next u
End Function

Is anyone able to provide any suggestions on the possible cause of this error and how to resolve it?
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
In VBA you need to declare each variable type like this:

Dim wstime1 as String, wstime2 as String, wstime3 as String, wstime4 as String, wstime5 As String

otherwise the default Variant will apply.
 
Upvote 0
Ark68,

You have to declare each variable with its type, try the following:

Code:
Dim wstime1 As String, wstime2 As String, wstime3 As String, wstime4 As String, wstime5 As String
Dim lNumber1 As Long, lNumber2 As Long, lNumber3 As Long, lNumber4 As Long, lNumber5 As Long
 
Last edited:
Upvote 0
Thanks guys for your replies. That cleaned up things nicely.

I did not know that about variable declaration. I have used "my" technique of declaring multiple variables throughout my project thinking it was the standard. Now I learn it's just the opposite. Looks like I have to go back and make some more changes.
 
Upvote 0
Ark68,

Thanks for the feedback.

You are very welcome. Glad we could help.

And, come back anytime.
 
Upvote 0

Forum statistics

Threads
1,215,379
Messages
6,124,605
Members
449,174
Latest member
ExcelfromGermany

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