cancel
Showing results for 
Search instead for 
Did you mean: 

Swap | Interchange | Move Columns in an Excel

vinodchinthakin
Level 9
Hi,

I have an Excel having data ranging from columns A to Z, I have following requirements.

1. Column G along with values to be inserted/moved after Column B. 
2. Column E and Column F needs to swap their positions.
3. Needs to delete Columns P, S, and W.

Do we have any specific actions for the above.

Thanks!

------------------------------
vinod chinthakindi
------------------------------
5 REPLIES 5

Here is the code stage that you can use for deleting columns

27595.png
Dim wb, ws, excel, sheet As Object

wb = GetWorkbook(Handle, Workbook)
ws = GetWorksheet(Handle, Workbook, Worksheet)

wb.Activate()
ws.Activate()

excel = ws.Application
sheet = excel.ActiveSheet

ws.Columns(Range).EntireColumn.Delete

------------------------------
Shashank Kumar
DX Integrations Partner Consultant
Blue Prism
Singapore
+6581326707
------------------------------

PvD_SE
Level 12
Hi Vinod,

There's a collection action 'Get column from collection with header'. It lets you extract a full column from a collection to a new collection. Another action is 'Add column', that lets you add and existing column from a collection to a new collection. The thing to do is use either action on all each column in the order you'd like them to show up in your new collection.

------------------------------
Happy coding!
---------------
Paul
Sweden
------------------------------
Happy coding!
Paul, Sweden
(By all means, do not mark this as the best answer!)

Hi Paul, Thanks for the solution. But I don't want to read excel data to collection. I want to Sort Columns positions within Excel.

------------------------------
vinod chinthakindi
------------------------------

Hi @shashank.kumar280 Thanks for the solution. For deleting multiple columns, how to provide range value.? For example I want to delete Columns P, S, and W. in a single go instead of calling delete column action thrice!

------------------------------
vinod chinthakindi
------------------------------

Hi Vinod,

In that case there's always the 'Copy and Paste Worksheet Range' action. It is and out-of-the-box action in the BP VBO for Excel and if you can trust the help-text (of which there is none) it might just do exactly what you want.

------------------------------
Happy coding!
---------------
Paul
Sweden
------------------------------
Happy coding!
Paul, Sweden
(By all means, do not mark this as the best answer!)