Row value to adjacent columns

Hi All,
I need to swap the rows value to adjacent column and so on Please find the scenario below. where yellow is the input and I need output as blue

Hi @shiveshk4

Check the below video to transpose the data in the datatable.

Hope it helps!!

1 Like

@shiveshk4

  1. Use the “Read Range” activity to read the data from the Excel file into a DataTable (let’s call it inputDataTable).
  2. Use a For Each Row activity to loop through each row in inputDataTable.
  3. Inside the loop, use an Assign activity to swap the values between columns A and B for each row
Assign activity:
Dim tempValue As String = row("ColumnA").ToString()
row("ColumnA") = row("ColumnB").ToString()
row("ColumnB") = tempValue

Replace “ColumnA” and “ColumnB” with the actual column names in your DataTable.
4. After the For Each Row loop, use the “Write Range” activity to write the updated DataTable back to the Excel file.

Hope it works!!

1 Like

Hi Thanks for the video , but as you see the problem statement it is not what I need.

Hi Vrdabberu,

There is no column B as you see in Input (Yellow marked) , there is only one column i.e. A

Hi @shiveshk4
’ Step 1: Read the input table
Dim inputTable As DataTable = New DataTable()
inputTable = ReadRange(“PathToYourInputExcelFile”, “Sheet1”)

’ Step 2: Create a new DataTable for the output
Dim outputTable As DataTable = New DataTable()

’ Step 3: Loop through the rows and columns of the input table
For rowIndex As Integer = 0 To inputTable.Rows.Count - 1
For colIndex As Integer = 0 To inputTable.Columns.Count - 1
Dim currentValue As String = inputTable.Rows(rowIndex)(colIndex).ToString()

If the output table doesn’t have enough rows, add a new one
If colIndex >= outputTable.Rows.Count Then
outputTable.Rows.Add()
End If

If the output table doesn’t have enough columns, add a new one
If rowIndex >= outputTable.Columns.Count Then
outputTable.Columns.Add()
End If

Swap the value with the adjacent row and column in the output table
outputTable.Rows(colIndex)(rowIndex) = currentValue
Next
Next

Step 4: Write the output table to Excel
WriteRange(“PathToYourOutputExcelFile”, “Sheet1”, outputTable)

1 Like

@pravallikapaluri

Thanks for the reply.
could you please give a screenshot of the studio code or a xaml file, that would be really helpful.