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

Scott Chou 96 Reputation points

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

No comments
{count} votes

Accepted answer
  1. Scott Chou 96 Reputation points

    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!

3 additional answers

Sort by: Most helpful
  1. Tom van Stiphout 1,526 Reputation points MVP

    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?

  2. Tom van Stiphout 1,526 Reputation points MVP

    The CDbl wrapper is superfluous. Remove it.

  3. Tom van Stiphout 1,526 Reputation points MVP

    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 :-(