ByRef argument type mismatch

roscoe

Well-known Member
Joined
Jun 4, 2002
Messages
1,046
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Take 2

I have a function that converts Zulu time (or GMT if preferred) to local time (accounting for Daylight savings as appropriate) that has worked for years. Never had an issue. Today, I'm adding new code that requires such a conversion but the new code fails per the "ByRef argument type mismatch" error when I call the function. The function in question requires a DATE type value and I've verified that is what I'm sending it. I'm lost at this point.

Any hints as to what to look for would be greatly appreciated!

Thanks!

(Note: I can't use the built-in help function because Microsoft in their infinite wisdom now keeps the help files online...but my system is off the grid for proprietary reasons and can no longer access help files)
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Please post your function code, and how you are calling it.
 
Upvote 0
When passing arguments ByRef you are referencing the original value in the calling procedure which can be changed in the function and should therefore, be of same data type otherwise a mismatch error can occur.

If you do not need to reference the original value in your function then I suggest that you change its parameter to ByVal then only the value of the argument (a copy) is sent and the original argument is left intact. Any changes made in then function will not reflect in the original argument.


If you are still having problems, then suggest you provide copy of your function – plenty here to offer advice

Dave
 
Upvote 0
Please post your function code, and how you are calling it.
That's a challenge since my computer is not internet-connected. I'll have to find time to type in it.
When passing arguments ByRef you are referencing the original value in the calling procedure which can be changed in the function and should therefore, be of same data type otherwise a mismatch error can occur.

If you do not need to reference the original value in your function then I suggest that you change its parameter to ByVal then only the value of the argument (a copy) is sent and the original argument is left intact. Any changes made in then function will not reflect in the original argument.

Dave
My function didn't specify ByRef or ByVal...I assume the latter is the default which is part of the reason I'm a bit confused.
 
Upvote 0
That's a challenge since my computer is not internet-connected. I'll have to find time to type in it.
Please understand that it is a big challenge for us to try to help without being able to see the code!

Do you have a thumb drive or something to that effect where you could take a copy from your computer, and copy it to a computer that does have internet access?
 
Upvote 0
I understand...due to proprietary rules I can't digitally transfer files off my workstation. It's a pain in the butt but it is what it is.
 
Upvote 0
Found the problem...I have an explicit call that requires a DIM statement for every variable. I was passing a variable that was not declared. Why it took 69 run attempts before VBA finally pointed that out is beyond me but there you have it. Thanks to all who weighed in
 
Upvote 0
My function didn't specify ByRef or ByVal...I assume the latter is the default which is part of the reason I'm a bit confused.

If not specified, then passing ByRef is the default - If you do not need to do this then pass your argument ByVal

Rich (BB code):
Function myfunction(ByVal myparameter As Double) As Double

End Function

Glad you resolved your issue.

Dave
 
Upvote 0
Found the problem...I have an explicit call that requires a DIM statement for every variable. I was passing a variable that was not declared. Why it took 69 run attempts before VBA finally pointed that out is beyond me but there you have it. Thanks to all who weighed in
Sounds like maybe "Option Explicit" wasn't turned on before, but is now.
It is a good idea to always use this, which forces you to declare all your variables before using them.
It helps avoid typos, and helps to ensure that the code is running as it should (i.e. you aren't feeding a text field into a numeric field).
 
Upvote 0
"Option Explicit" has been in my project from day 1. Not sure the undeclared variables were sneaking by. Other weirdness was going on as well. Example, I was stepping through a subroutine to debug when it would suddenly jump out of the subroutine. Repeating it would jump out at a different point. I think VBA had developed cobwebs. Once I saved my work, closed, and reopened the file it behaved normally again (to include yelling at me for the undeclared variables).
 
Upvote 0

Forum statistics

Threads
1,214,968
Messages
6,122,509
Members
449,089
Latest member
RandomExceller01

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