Using Excel math functions in VB .NET

brazilnut52

Member
Joined
Feb 7, 2003
Messages
16
I am trying to envoke the Sum function on a range in VB .NET. I am getting an exception: Object Reference not set to an instance of an object.

here is my class:

Public Class generalFormatFunctions

Private ws As Excel.Worksheet

Sub New(ByVal worksheet As Excel.Worksheet)
ws = worksheet
End Sub

Public Function DeleteInvalidRows()
Dim colNumStart As Integer = 2
Dim wsFuncs As Excel.WorksheetFunction

Delete all rows that have 0 sum - assuming numbers start in col 2
Dim lastCol = ws.UsedRange.Columns.Count
Dim i As Integer
For i = ws.UsedRange.Rows.Count To 1 Step -1

If wsFuncs.Sum(ws.Range(ws.Cells(i, colNumStart), ws.Cells(i, lastCol))) = 0 Then
ws.Cells(i, 1).EntireRow.Delete()
End If

Next i
End Function
End Class

another class invokes this class and passes in a worksheet object. The exception occurs in this line: If wsFuncs.Sum(ws.Range(ws.Cells(i, colNumStart), ws.Cells(i, lastCol))) = 0 Then

Any ideas

thanks brazilnut
 
you need to declare an Application...
Code:
Dim xApp As Excel.Application
xApp = CType(CreateObject("Excel.Application"), Excel.Application)
Dim wsFuncs As Double (maybe)

wsFuncs = xApp.WorksheetFunction. Continue your function here
 
Back
Top