0

When I try to run the function below the macro menu pops up, so I created a Sub to call the function and now I get the error "Argument not optional".

The function is attempting to do a match which I then hope to use to do an array index match. https://bettersolutions.com/vba/arrays/searching.htm

Sub Repossession_Match()

Dim Inflation_Bucket, Inflation_Bucket_Label As Variant



Call TwoDimensional

End Sub


Public Function TwoDimensional(ByVal Inflation_Bucket_Label As Variant, _
                               ByVal Inflation_Bucket As Variant) _
                               As Boolean

Dim Inflation_Bucket, Inflation_Bucket_Label As Variant
Inflation_Bucket = Range("Costs.Inflation_Bucket")
Inflation_Bucket_Label = Range("Inflation.Inflation_Bucket_Label")

   Dim lrow As Long
   Dim lcolumn As Long

   For lrow = LBound(Inflation_Bucket_Label, 1) To UBound(Inflation_Bucket_Label, 1)
      For lcolumn = LBound(Inflation_Bucket_Label, 2) To UBound(Inflation_Bucket_Label, 2)
         If (Inflation_Bucket_Label(lrow, lcolumn) = Inflation_Bucket) Then
            TwoDimensional = True
            Exit Function
         End If
      Next lcolumn
   Next lrow
End Function
1
  • TwoDimensional has two arguments, neither of which are you passing. You probably need to read up on this topic as you are defining both these in your code so you can remove them. Commented Aug 1, 2019 at 16:27

1 Answer 1

0

You want something more like this:

Sub Repossession_Match()

    Dim Inflation_Bucket, Inflation_Bucket_Label As Variant

    Inflation_Bucket = Range("Costs.Inflation_Bucket")
    Inflation_Bucket_Label = Range("Inflation.Inflation_Bucket_Label")

    MsgBox TwoDimensional(Inflation_Bucket_Label, Inflation_Bucket)

End Sub


Public Function TwoDimensional(ByVal Inflation_Bucket_Label As Variant, _
                               ByVal Inflation_Bucket As Variant) _
                               As Boolean
   Dim lrow As Long
   Dim lcolumn As Long

   For lrow = LBound(Inflation_Bucket_Label, 1) To UBound(Inflation_Bucket_Label, 1)
      For lcolumn = LBound(Inflation_Bucket_Label, 2) To UBound(Inflation_Bucket_Label, 2)
         If (Inflation_Bucket_Label(lrow, lcolumn) = Inflation_Bucket) Then
            TwoDimensional = True
            Exit Function
         End If
      Next lcolumn
   Next lrow
End Function
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.