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()