what i am trying to do is make a program to read an excel file that i already have , choose certin columns depending on its header title then paste these columns into sheet2 .
the problem is when i check for the columns i want to extract it gives me this error "Object reference not set to an instance of an object".
this is the code i am using to extract the value of a certin cell while looping throw a row and if the value of the cell = "Sample" it changes the value of another cell with "Pass"..
Imports Excel = Microsoft.Office.Interop.Excel
Imports System.IO
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartTesting.Click
Dim oXL As Excel.Application
Dim oWB As Excel.Workbook
Dim oSheet As Excel.Worksheet
' start excel application
oXL = New Excel.Application
oXL.Visible = True
' Get a new workbook.
oWB = oXL.Workbooks.Open(C:\filepath.xls)
oSheet = oWB.ActiveSheet
' just to show me the value of the cell
MsgBox(oSheet.Cells(1, 1).Value.ToString, MsgBoxStyle.OkOnly)
' starting the loop
Dim i As Integer = 1
For i = 1 To 128
If oSheet.Cells(1, i).Value.ToString = "Sample" Then
oSheet.Cells(2, 1) = "Pass"
End If
Next i
End Sub
but it does not work :(
thank you for helping