Using invoke code to delete excel duplicate rows

Dear all,

I tried to put following code to invoke code editor, but I dont know how to write it correctly:

Sub DeleteRows()
    With ActiveSheet
        Set Rng = Range("A1", Range("B1").End(xlDown))
        Rng.RemoveDuplicates Columns:=Array(1, 2), Header:=xlYes
    End With
End Sub

As I can import Microsoft.Office.Interop.Excel.Workbook also it works fine, but I don’t know how to convert above code into code editor in uipath.


What does it mean? I know two ways to invoke VBA code:

  • add code to Excel worksheet as a new module and then use “invoke vba” activity for invoke macros by name
  • or write VBA code to .txt file and then invoke it. See example

I changed your macro some:

Sub DeleteRows()
    Dim Ws As Worksheet
    Set Ws = ActiveWorkbook.ActiveSheet
    Dim rng As Range
    Set rng = Ws.Range("A1", Ws.Range("B1").End(xlDown))
    rng.RemoveDuplicates Columns:=Array(1, 2), Header:=xlYes
End Sub

hi Ivanco,

yes I can do this through invoke VBA code, but I have to change it to invoke code and put these code into code editor.

“into code editor” - where? in Excel? my advice: write and debug VBA code in Excel code editor, and then invoke using UiPath.

its an activity called invoke code

sorry, sir i don’t understand the problem.
For “invoke VBA” you must put VBA code to .txt file (see example by link bellow).
For “execute macro” activity you must put VBA code to Excel file.

Hy @raymondhui,

I am an excel vba expert myself, I love you vba!

However I suggest you try to do what you need using Uipath Commands, please check the insert/delete rows activity.