ByRef Argument Mismatch while Calling a Function

Valryn

New Member
Joined
Jul 25, 2011
Messages
2
Hello all,

I'm new to mrexcel and new to VBA so I really hope this isn't a waste of everyone's time. I apologize if this has been asked elsewhere and I haven't been able to understand it correctly.

I have two functions that both work correctly on their own, but I would like to call one of them in a loop. This may not be the best way to set this up but I'm kinda looking for a quick and dirty solution at the moment.

So here's what I have:

Code:
Sub formatAll()

    Dim lastRow As Long
    
    lastRow = findLastRow(1)
    
    For n = 1 To lastRow Step 6
    
        Call formatCompany(n)
        
    Next n

End Sub

When I try to run it I get a compile error: "ByRef argument type mismatch"

The error originates from trying to call formatCompany() with "n".

Any help you could offer would be greatly appreciated.

Thanks, Valryn
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
This is because you haven't declared n. If you don't declare it, it is created as a variant. You need to look at the function formatCompany and see what the parameter is declared as and then declare n as the same data type.

So you'll have something like

Function formatCompany(byref x as integer) as Integer

Then you need to put Dim n as Integer in the formatAll procedure
 
Upvote 0
Ah, thank you so much for the quick response. Yes, after declaring the loop variable as the correct data type for formatCompany() it worked perfectly. I wasn't aware that the loop variable was made as a variant, I just figured it magically worked itself out somehow. Haha. Anyway, thanks again!

Valryn
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,626
Members
452,933
Latest member
patv

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