web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Automate
Answered

List to Data Table

(0) ShareShare
ReportReport
Posted on by 27

I have Some lists which have many row values, I want to add those lists to individual columns in data table and write in excel.(Please avoid looping).

 

I have the same question (0)
  • VishnuReddy1997 Profile Picture
    2,666 Super User 2026 Season 1 on at

    Hi @Raju25 ,

     

    As per my understanding what you have elaborated, and I have created a solution.

    Please find the attached solution. 

    Pre-requisite: Create an Excel Template with 2 sheets.

     

    VishnuReddy1997_1-1711538744828.png

     

    Code:

    Variables.CreateNewList List=> List
    SET List TO ['Vishnu', 'Vardhan', 'Reddy']
    Excel.LaunchExcel.LaunchAndOpenUnderExistingProcess Path: $'''C:\\Users\\vr79540\\OneDrive - Cyient Ltd\\Desktop\\Power Automate Desktop\\Practice\\Text File\\Output.xlsx''' Visible: True ReadOnly: False Instance=> ExcelInstance
    Excel.WriteToExcel.WriteCell Instance: ExcelInstance Value: List Column: $'''A''' Row: 1
    Excel.ReadFromExcel.ReadAllCells Instance: ExcelInstance ReadAsText: False FirstLineIsHeader: False RangeValue=> ExcelData
    Excel.CloseExcel.CloseAndSave Instance: ExcelInstance
    @@copilotGeneratedAction: 'False'
    Scripting.RunVBScript.RunVBScript VBScriptCode: $'''Const xlUp = -4162
    Const xlToLeft = -4159
    Dim objExcel, objWorkbook, objSheet
    Dim lastRow, rowData(), i
    \' Create Excel objects
    Set objExcel = CreateObject(\"Excel.Application\")
    objExcel.Visible = True
    Set objWorkbook = objExcel.Workbooks.Open(\"C:\\Users\\OneDrive\\Desktop\\Power Automate Desktop\\Practice\\Text File\\Output.xlsx\") \' Update the path to your Excel file
    Set objSheet = objWorkbook.Sheets(1)
    Set objSheet2 = objWorkbook.Sheets(2)
    \' Find the last used row in column A
    lastRow = objSheet.Cells(objSheet.Rows.Count, 1).End(xlUp).Row
    \' Resize the array based on the number of rows
    ReDim rowData(lastRow)
    \' Read data from Excel sheet (assuming data is in column A)
    For i = 1 To lastRow
    rowData(i) = objSheet.Cells(i, 1).Value
    Next
    \' Write data to Excel sheet in a single row
    For i = 1 To lastRow
    objSheet2.Cells(1, i).Value = rowData(i)
    Next
    \' Clean up
    objWorkbook.Save
    objWorkbook.Close
    objExcel.Quit
    Set objSheet = Nothing
    Set objWorkbook = Nothing
    Set objExcel = Nothing''' ScriptOutput=> VBScriptOutput2


    (Note:- if you got your solution you can mark as solution and gives kudos)

     

    Thanks & Regards

    Vishnu Reddy

     

     

     

  • Raju25 Profile Picture
    27 on at

    Thanks for your fast reply, here i want to write two or more lists to the excel or data table without using looping and more than one write to excel action. Each list have one column and many row values.
    My flow scenario: I have used run javascript action and collected lot of data in form of array but you know for run javascript action stores output variable in a string. I converted it to lists using split text action. Like that i have gathered many lists. I want to combine those lists into one data table (each list in one column). Please provide a solution without using looping and more than one write to excel action.

  • Verified answer
    kinuasa Profile Picture
    799 Most Valuable Professional on at

    How about adding a column to a data table using the “Run .NET script” action, as shown below?

     

    PAD_AddColumnsToDataTable_01.jpgPAD_AddColumnsToDataTable_02.jpgPAD_AddColumnsToDataTable_03.jpg

     

    SET UserDataTable TO { ^['Name'], ['Cart'], ['Tammy'], ['Jimmy'], ['Aloisia'], ['Kearney'] }
    SET GenderList TO ['Male', 'Male', 'Male', 'Female', 'Male']
    SET ColumnName TO $'''Gender'''
    Scripting.RunDotNetScript Language: System.DotNetActionLanguageType.CSharp Script: $'''srcTable.Columns.Add(colName, typeof(String));
    for (int i = 0; i < srcList.Count; i++)
    {
     srcTable.Rows[i][colName] = srcList[i];
    }''' @'name:colName': ColumnName @'type:colName': $'''String''' @'direction:colName': $'''In''' @'name:srcTable': UserDataTable @'type:srcTable': $'''Datatable''' @'direction:srcTable': $'''InOut''' @'name:srcList': GenderList @'type:srcList': $'''List''' @'direction:srcList': $'''In''' @srcTable=> UserDataTable2
  • Raju25 Profile Picture
    27 on at

    Thank you for providing the efficient solution which consumes less time than anything else, may i follow you in any social media.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 238 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 225

#3
Haque Profile Picture

Haque 181

Last 30 days Overall leaderboard