VB.Net Help with For Loop

I have the below VB.Net code currently being executed in UiPath using the “Invoke Code” activity. The For loop does not give any syntax error but the If statement does not seem to be executing. Is there a problem with the way I referenced the range in the loop ie ws.range("F" & i).Value ?

'create instances of excel and open final file
Dim excel As Microsoft.Office.Interop.Excel.Application
Dim wb As Microsoft.Office.Interop.Excel.Workbook
Dim ws As Microsoft.Office.Interop.Excel.Worksheet
	excel = New Microsoft.Office.Interop.Excel.ApplicationClass
	wb = excel.Workbooks.Open("FilePath.xlsx")
	ws= DirectCast(wb.Worksheets(1),Microsoft.Office.Interop.Excel.Worksheet)
	
'Delete the first two rows of the worksheet
		ws.Range("A1").EntireRow.Delete
		ws.Range("A1").EntireRow.Delete
'Define the last row if the worksheet
Dim LastRow As Long
	LastRow = ws.UsedRange.Rows.Count
'Delete the last row (the Total column)
		ws.Range("A" & LastRow).EntireRow.Delete
LastRow = ws.UsedRange.Rows.Count

Dim i As Long

For i = 2 To LastRow
    If ws.range("F" & i).Value Is "Declined"  Then 
		ws.range("F" & i).EntireRow.ClearContents
	  
     End If
  
 Next i
	  
'Save and close application
excel.activeworkbook.save
excel.Workbooks.close()
excel.Quit()

Hi, welcome to the community!
I would change this part:
ws.range("F" & i).Value.ToString = "Declined"

Hi! I received the below error. Is there another line that would need to be changed after changing to .ToString?

“Error ERROR Validation Error Compiler error(s) encountered processing expression “row.”.
Identifier expected. Sequence.xaml”

that part just needs a .ToString after the .Value or you never going to match an Object against a String…

Hi, it still does not clear the contents of the row. Am I missing an aspect of the loop? The rows marked with Declined are still in the spreadsheet after running.

Well, that i dont know, my help is just part of the problem i guess, i can help you do the same using the activities if you are interested…