How to loop through excel columns and append a certain range?


This is an example at what I need to do in scale. Essentially, if we go off column index I need every even column to append into column A and every odd column to append into column B. Thanks in advance!

Hi @Ben_Putney ,

We could check with the below Expression :

OutputDT = DT.Columns.Cast(Of DataColumn).Select(Function(c)c.ColumnName).Chunk(2).SelectMany(Function(x)DT.DefaultView.ToTable(false,x).AsEnumerable).CopyToDatatable

Here, DT is the Input Datatable and OutputDT is the prepared Datatable with 2 Columns as from the Required Output representation, you would want to club each 2 columns and combine it back to the first two column data.

From the Debug :


This worked exactly as you explained, I appreciate your help. Thank you!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.