VBA debug compile error

ouvay

Board Regular
Joined
Jun 9, 2022
Messages
131
Office Version
  1. 2019
Platform
  1. Windows
Hello, I am working on this code that matches multiple criteria and then does a bunch of copy pasting (simply put)

I am looping through my array, sending through the criteria to the UDF, which loops through the second data region to find the match and paste the values I want pasted

simple enough in theory... but when I try and send the criteria through for referencing ... I get an error...

Here is my basic code (haven't finished obviously)

VBA Code:
Sub connect()

    Dim hdfcwb As Workbook: Set hdfcwb = Workbooks.Item("Payment Control - HDFC Leg.xlsm")
    Dim hdfc As Worksheet: Set hdfc = hdfcwb.Worksheets(1)
    Dim a(2 To hdfc.Rows.Count, 1 To 6) As Integer
    
    For r = 2 To UBound(a, 1)
        match(a(r, 3), a(r, 4), a(r, 6))
        
    Next r
    
End Sub


Function code
VBA Code:
Function match(buyer As Long, sponsor As Long, pay As Integer)

End Function

Error
1660279318472.png

1660279333295.png


Not sure why the "=" is required?

TIA
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
A VBA function returns some value(s).

Any code calling that function needs to assign or use that value somehow, e.g.

Rich (BB code):
SomeVariableName = match(a(r, 3), a(r, 4), a(r, 6))

BTW, you'll need to declare a in two steps:

VBA Code:
Dim a() As Long
    
ReDim a(2 To hdfc.Rows.Count, 1 To 6) As Long

But you should really make a only as big as you need, rather than including 1m+ rows.

I'd probably also change the name of the function to MyMatch, say. Generally it's better to avoid names that already mean something in Excel or VBA. It shouldn't be an issue here with match, but sometimes it will cause problems with your code.
 
Upvote 0
A VBA function returns some value(s).

Any code calling that function needs to assign or use that value somehow, e.g.

Rich (BB code):
SomeVariableName = match(a(r, 3), a(r, 4), a(r, 6))

BTW, you'll need to declare a in two steps:

VBA Code:
Dim a() As Long
   
ReDim a(2 To hdfc.Rows.Count, 1 To 6) As Long

But you should really make a only as big as you need, rather than including 1m+ rows.

I'd probably also change the name of the function to MyMatch, say. Generally it's better to avoid names that already mean something in Excel or VBA. It shouldn't be an issue here with match, but sometimes it will cause problems with your code.
Thank you! That is insightful!

sets me off in the general direction I need to be headed in! :)
 
Upvote 0
FWIW, you don't have to use the value returned from a function but if you don't, there shouldn't be parentheses around the function call (unless you use the Call statement) so it would be either:

Code:
match a(r, 3), a(r, 4), a(r, 6)

or:

Code:
Call match(a(r, 3), a(r, 4), a(r, 6))
 
Upvote 0
FWIW, you don't have to use the value returned from a function but if you don't, there shouldn't be parentheses around the function call (unless you use the Call statement) so it would be either:

Code:
match a(r, 3), a(r, 4), a(r, 6)

or:

Code:
Call match(a(r, 3), a(r, 4), a(r, 6))
Thats very useful! :o Thanks!
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,623
Latest member
Techenthusiast

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