Need Help fixing VBA Type Mismatch Error passing a Double as argument

Scott Chou 96 Reputation points
2021-04-15T21:14:04.8+00:00

It seems so simple but I've tried many variations of this and I can't get it to work. It immediately returns a compile error on this line:

Sub SplitAdjustment(split As Double)
. . .
End Sub

at the calling end, I have:

Dim split As Double
Call SplitAdjustment(CDbl(split))

I started out with just Call SplitAdjustment(split) but failed
also tried using ByVal split at either end and at both ends but failed

0 comments No comments
{count} votes

Accepted answer
  1. Scott Chou 96 Reputation points
    2021-04-16T04:24:46.943+00:00

    I found the problem and it appears to be a rookie mistake on my part. The yellow highlighted debugger stopping point at the subroutine header was a coincidence. The error was INside the subroutine. A very straightforward ByRef error

    Sorry and thanks for your time!

    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Tom van Stiphout 1,621 Reputation points MVP
    2021-04-16T03:42:49.7+00:00

    This code looks OK to me. The problem may be somewhere else. Set breakpoints and carefully step through.

    You do have Option Explicit in place per best practices, and your code does compile (Debug > Compile), correct?

    0 comments No comments

  2. Tom van Stiphout 1,621 Reputation points MVP
    2021-04-16T03:43:31.91+00:00

    The CDbl wrapper is superfluous. Remove it.

    0 comments No comments

  3. Tom van Stiphout 1,621 Reputation points MVP
    2021-04-16T03:45:28.71+00:00

    Sub SplitAdjustment(split As Double)

    I would CERTAINLY use ByVal in this case, because presumably the procedure has no intention of returning a changed "split" to the caller.
    But it does not explain the main issue :-(

    0 comments No comments