Excel 2007
i am trying to create a function to do a sumif using workbookFunction in VBA so that I can pass in a named Range and worksheet name via a control row on a worksheet to create the data and formula's where needed.
However I just can't get it to work. It seems to stop on the line i have highlighted in red. Any help appreciated on this.
i am trying to create a function to do a sumif using workbookFunction in VBA so that I can pass in a named Range and worksheet name via a control row on a worksheet to create the data and formula's where needed.
However I just can't get it to work. It seems to stop on the line i have highlighted in red. Any help appreciated on this.
Code:
Public Function GetWSValue(strFrom As String, rngNRColumn As Range) As Double
Dim icolumn As Integer
Dim rngSB_ASGID As Range
Dim rngThisCell As Range
Dim strRange As String
Dim res As Double
get position of range using Sales worksheet
icolumn = ThisWorkbook.Sheets("Sales").Range("NRSALES_SB_ASGID").Column
With ThisWorkbook.ActiveSheet
'// sets range to active worksheet
Set rngSB_ASGID = .Range(ThisWorkbook.Sheets("Sales").Range("NRSALES_SB_ASGID").Address)
Set rngThisCell = .Cells(Application.ThisCell.Row, rngSB_ASGID.Column)
End With
[COLOR=red]res = Application.worksheetFunction.SumIfs(rngSB_ASGID, rngThisCell, rngNRColumn)[/color]Debug.Print res
GetWSValue = res
End Function