HI. I’m new, and I’m doing my first automation. I can’t share the code, but what I need to do is to delete some useless rows in an Excel file at the end of it. Basically, I have a report with some rows of date. I copy these rows in another file used as template with some formulas in the columns AR-BB. Unfortunately, my template with the formulas has more rows (because it’s used for more reports) than the report itself. I want to delete these final rows with useless formulas. I want to use a macro.
The code is:
Sub eliminaRighe()
Worksheets(“Sheet1”).Activate
Dim lastRow As Integer
lastRow = ActiveSheet.UsedRange.Rows.Count
Do While IsEmpty(Range(“A” & lastRow).Value)
Range(“a” & lastRow).EntireRow.Delete
lastRow = lastRow - 1
Loop
End Sub
It works fine as macro in Excel, but it doesn’t work (it doesn’t do anything) when I invoke it through UiPath. I invoke it inside an “excel scope application” activity I specify the path and the name “eliminaRighe”. Can someone help me?
Sub eliminaRighe()
Sheets(“Sheet1”).select
Dim lastRow1 As Integer
Dim lastRow2 As Integer
lastRow1 = cells(rows.count,1).end(xlup).row
lastRow2 = cells(rows.count,44).end(xlup).row
Range(cells((lastRow1+1) ,1),cells(lastRow2,54)).clearcontents
End Sub
Hi. Thank you for answering. I tried your code, like mine it works if I use it manually, but when I use it as macro in uiPath It doesn’t do anything. I mean, I put a msgBox and I saw that UiPath runs the macro because it creates the message box but it looks like it doesn’t save the modifies. Could it be this the problem?
Sub eliminaRighe()
Sheets(“Sheet1”).select
Dim lastRow1 As Integer
Dim lastRow2 As Integer
lastRow1 = cells(rows.count,1).end(xlup).row
lastRow2 = cells(rows.count,44).end(xlup).row
Range(cells((lastRow1+1) ,1),cells(lastRow2,54)).clearcontents
Activeworkbook.save
End Sub