Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

worksheetFunction SumIfs help! creating UDF to pass variable.

Status
Not open for further replies.

neemi

Programmer
May 14, 2002
519
GB
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.


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
 
HAHAHAHA!!!

SOLVED!

As soon as I posted this I saw my mistake! spent two days pulling my hair out and the mistake was I mistakenly typed "SumIfs" instead of "SumIf"!!!!!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top