How to delete columns in Excel file

Dear Team,

How to delete columns in Excel file

1 Like

Hello dear,

You should use following code for delete excel file column

Regards and Thanks,
Yogesh Shirsath

3 Likes

Thanks Yogesh,but I want to delete specific columns eg. from G:AA, how to select these columns, after selection I can use the short cut key you have mentioned

Hello,

There is no method for that in uipath but you can use .net method that is available in .net framewor and you can invoke any method from .net using invoke activty, you can learn about deleting rows here

Try this and comment your outcome please.

testtt(Autosaved).xaml (9.1 KB)

Well, actually there are few workarounds.

  1. If you’re working with an Excel Table you can directly use Delete Column activity

  2. Though not so obvious, there are many things you can achieve via UI Automation and shortcut keyboards.

Let’s say you want to delete column C. This sequence of activities will work: Go To C1, ALT+H, D, C. Make sure you remove the Activate on the last two Type Activities. DeleteColumnC.xaml (8.0 KB)

Now, if you want to delete columns from G to AA you just need to repeat deleting column G 21 times.

This link will definitely help.

2 Likes

Lol, how about just “write value” , select the range you want and put “” on the value?? That will put it all blank. not deleted.

It works if you don’t want to bring the columns at right side to left one…

1 Like

Hello. Just to propose a different method you could use the Activity Select Range and specify all sorts of values:

  1. Individual cells (A1)
  2. A range (A1:B2)
  3. A column (A)
  4. A column range (A:I)

Then you just need to send a delete hotkey. Just remember to send the hotkey in the sheet itself.

1 Like

Actually your idea helped me a lot. Thank you very much:)

Hi @beesheep

Thanks. It is deleting only one column name. I want to delete multiple column names but the arguments are not taking multiple names. Is there any other method?

Thanks,
Ula

@Boopathi You can use a for loop to delete Multiple Columns

I am able to give only one column name in invoke method activity and using remove function.

@Boopathi Do yoiu know what are the multiple Columns You want to delete?

@supermanPunch Yes, more than 20 columns i need to delete and keeping only 9 columns

@Boopathi If you just want to Keep 9 Columns, then you can use Filter Datatable Activity and in Keep Columns Section of Filter Wizard , Mention Column Names that you want to Keep

Hey @Boopathi

You can also use DefaultView, like this:

dt = dt.DefaultView.ToTable(False, “Column1”, “Column2”, “Column3”)

In this way, in dt you will store the columns you desire.