Hey Guys!
I'm trying to add objects from a class I created using data from an excel worksheet to a list using a for loop
When I run it I receive "System.NullReferenceException was unhandled by user code Message=Object reference not set to an instance of an object." Any help or suggestions would be great!Code:Dim someParts As New List(Of Parts) Dim excel As New Excel.Application() Dim wb As Excel.Workbook = excel.Workbooks.Open(OpenFileDialog1.FileName()) Dim ws As Excel.Worksheet = TryCast(excel.ActiveSheet, Excel.Worksheet) Dim range As Excel.Range range = ws.UsedRange For row = 2 To range.Rows.Count someParts.Add(New Parts(ws.Cells(row, 3).Value2.ToString, ws.Cells(row, 2).Value2.ToString, Split(ws.Cells(row, 6).Value2.ToString, "<>"), ws.Cells(row, 4).Value2)) Next




Reply With Quote
