Functions in VBA

welshgasman

Well-known Member
Joined
May 25, 2013
Messages
1,402
Office Version
  1. 2019
  2. 2007
Platform
  1. Windows
Hi all,

I created a function to calculate a value to be returned from a matrix in a sheet.

The function is below

As you can see I have tried to break it down to find where the error lies.
If I use

Code:
=IF(C126="Investment",introrate(A126,C126,D126,I126),introrate(A126,C126,F126,I126))
as the formula, it works for some of the options, but where the amount passed in is > 14200 and pstrFeeType = IFA, I get #Value in the sheet, yet if I use
the values of the cells in the immediate window such as

? introrate("CC Fee","IFA",38545.34,"TPA Service")
I get the value 0 which is correct.?

What am I missing please?

Code:
Function IntroRate(pstrProdType As String, pstrFeeType As String, pcurAmount As Currency, pstrIntroducer As String)
' This function will return the % payable to an Introducer
Dim strColHeader As String
Dim iRow As Integer, iCol As Integer


If pcurAmount < 14200 Then   
    If pstrFeeType = "IFA" Then
        strColHeader = Sheets("Matrix").Range("B1").Value
    Else
        strColHeader = Sheets("Matrix").Range("C1").Value
    End If
Else
    Select Case pstrProdType
        Case "JL Fee"
            strColHeader = Sheets("Matrix").Range("E1").Value
        Case "JL Invest"
            strColHeader = Sheets("Matrix").Range("F1").Value
        Case "CC Invest"
            strColHeader = Sheets("Matrix").Range("G1").Value
        Case "OT Fee"
            strColHeader = Sheets("Matrix").Range("H1").Value
        Case "CC Fee"
            strColHeader = Sheets("Matrix").Range("D1").Value


    End Select
End If
iRow = WorksheetFunction.Match(pstrIntroducer, Sheets("Matrix").Range("A1:A30"), 0)
iCol = WorksheetFunction.Match(strColHeader, Sheets("Matrix").Range("A1:H1"), 0)
IntroRate = WorksheetFunction.Index(Sheets("Matrix").Range("A1:H30"), iRow, iCol)


    'IntroRate = WorksheetFunction.Index(Sheets("Matrix").Range("A1:H30"), WorksheetFunction.Match(pstrIntroducer, Sheets("Matrix").Range("A1:A30"), 0), WorksheetFunction.Match(strColHeader, Sheets("Matrix").Range("A1:H1"), 0))
    'Debug.Print IntroRate


End Function
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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