How to rearrange columns in Excel and duplicate one of them?

Hi All,

I’m stuck in this task :worried:

Example:

Input: From Sheet1
image

OutPut:To Sheet2
image

I tried using Filter Data Table but it does not admit duplicate columns:

image

Also, I’m trying with “Select” but I’m not pretty sure how to use it:

image

Note: Note: I can’t use unofficial activities :frowning:

Any help would be greatly appreciated! :slight_smile:

1 Like

There is no way to have same column name in a tabledata.
I recommend you to change name as price2 and to use SetOrdinal method.

assumption : dt is original tabledata.
[c# sample code]

  1. copy into new datatable
  2. add new column by Add Method with expression
    (new column value is filled as Price column value)
  3. change ordinal by SetOrdinal Method

DataTable newdt = dt.Copy();
newdt.Columns.Add(“Price2”,typeof(string),“Price”);
newdt.Columns[“Price2”].SetOrdinal(1);

Source Datatable
ID|Name|Price|Fee

New Datatable
ID|Price2|Name|Price|Fee

2 Likes