I am creating a vb.net application to update an excel spreadsheet. I access the excel file using Imports Microsoft.Office.Interop.
So far I can add data to the desired worksheet using hardcoded cell co-ordinates, for example :
sheet.Cells(3, 3) = mystring
I need to loop through each row to find the first row where each of the first 10 cells (A-J) contain no data so I can update those cells. I need to do it this way as columns K onwards may contain other data so I cant check for whole blank rows.
My attempt has started off just checking cell A in each row to begin with, trying to identify a blank/empty cell. If it worked I was thinking about using a for loop inside the do while loop too move along the cells in the row.
Using the following code I get a message box stating "System.__ComObject".
Dim rowcount As Integer = 0
Dim emptyrowfound As Boolean = False
Do While emptyrowfound = False
rowcount += 1
MessageBox.Show(sheet.Cells(rowcount, 1).ToString) ' attempt to view cell contents for testing purposes
If sheet.Cells(rowcount, 1).ToString = "" Then ' attempt to test if cell is blank/empty
emptyrowfound = True
End If
Loop
Once working I intend to apply cell updates like :
sheet.Cells(rowcount, 3) = mystring
...
Can anyone suggest a better way of checking and getting the row number?