Move specific column to a specifed location in an Excel sheet

You can do that using VB code :smiley: . You can do that using the data table as well.

  1. Read the entire excel and store in data table.
  2. Then use set ordinal which is available to move the columns to required position
  3. Write it back to excel

Please let me know if you are interested in VB code for this. Happy to share :slight_smile: @NiranjanKN

2 Likes

Hey, @HareeshMR @kaderms
I used the manual method, but all processes are carried out, but at the end the Final file won’t be saved.

And, to use by reading entire excel into a datatable, I didn’t find the set ordinal activity.

Thank you.

1 Like

Here is the reference formula for set ordinal

dt.Columns(column to be moved).SetOrdinal(column number to which the column to be moved)

1 Like

Hey, @HareeshMR

In this test file Test.xlsx (39.5 KB),
I need to filter the MST column by blanks, then move the BILT column to position of MATN, and then convert that entire BILT column to numbers.

Thank you.

1 Like

For this entire process, record the macro @NiranjanKN, then make it dynamic so that you can use it further as well

Dynamic in the sense, if the column BILT is at a specific and fixed column number, then it is not required else you need to make it dynamic

1 Like

Hey, @HareeshMR @aksh1yadav
Can you just share a code to execute the test file.

Thank you

1 Like

Use Invoke method for set ordinal
image

image

Target Object will be
Datatable…Columns(“columnname”)

2 Likes

I’m still getting an error in this method.

Thank you.

1 Like

Use write range after performing those moving column actions(invoke methods)
test Flow.zip (18.6 KB)

1 Like

Its still not working.

Thank you.

1 Like

Its working fine…with

1 Like

test Flow (2).zip (19.0 KB)
You just run this script it will give u the desired output

1 Like

@ImPratham45 @HareeshMR @kaderms
I tried the same code for my sample file and I’m getting an error that Value cannot be null.

Thank you.

1 Like

can you share your project folder

1 Like

Got it bro
The column name is : "BILT "
there are empty spaces aftre BILT
PLS REMOVE THOSE FROM excel file or add those in xmal workflow file in project

1 Like

Hey,
I got it.
Move Column.zip (50.3 KB)

Thank you.

Project.zip (66.0 KB)
run this script

Hi @NiranjanKN,

I have developed a activity to move the column inside excel. Here is the result.

Xmal Result…

NiranjanKN.zip (56.8 KB)

Regards
Balamurugan.S

1 Like

Thank you @balupad14

1 Like