Calling functions and mismatch errors

brncao

Board Regular
Joined
Apr 28, 2015
Messages
147
Code:
Private Sub TestFunctions()
    Dim flag As Range, EB As Range
    Set flag = Range("H82")
    Set EB = Range("K84")
    MsgBox SumCells(flag, EB)
End Sub

Function SumCells(flag As Range, EB As Range)
    Dim sumRng As Range
    Dim a As Currency, b As Currency
    Set sumRng = flag
    b = Abs(EB)
    a = flag
    
    Do Until a >= b
        If a <> b Then
            Set sumRng = Union(sumRng, Range(RangeOffset(sumRng)))
            a = WorksheetFunction.Sum(sumRng)
        End If
    Loop
    SumCells = sumRng
End Function
The issue is with passing along the arguments to a function. It says there's a mismatch. When I had the code all in one, it worked but was too cluttered. I decided to use functions to declutter it.

The function's job is to return a range of cells. i.e. A1:Z1, NOT the amounts in the cells.
 
Last edited:

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Sumcells is returning an array which msgbox can't display. Did you mean to assign a, rather than sumrng, as the result of sumcells?
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,543
Members
449,089
Latest member
davidcom

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