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 Platform Community / Forums / Power Automate / Combine excel column v...
Power Automate
Answered

Combine excel column values which start with name Email and add it send an outlook email Using Power Automate Desktop

(0) ShareShare
ReportReport
Posted on by 54

Combine excel column values which start with name Email and add it in To section of  send an outlook email. As we are unaware of number of Email columns it can contain 3 columns like Email1,Email2,Email3 or 5 Email columns  Email1,Email2,Email3,Email4,Email5. Not sure of number of columns containing email.

  • Preethi Ambati Profile Picture
    54 on at

    Excel.LaunchExcel.LaunchAndOpenUnderExistingProcess Path: $'''C:\\Users\\Test\\Downloads\\FilteredData.xlsx''' Visible: False ReadOnly: False Instance=> ExcelInstance
    Excel.GetFirstFreeColumnRow Instance: ExcelInstance FirstFreeColumn=> FirstFreeColumn FirstFreeRow=> FirstFreeRow
    Excel.ReadFromExcel.ReadCells Instance: ExcelInstance StartColumn: $'''A''' StartRow: 1 EndColumn: FirstFreeColumn - 1 EndRow: FirstFreeRow - 1 ReadAsText: False FirstLineIsHeader: True RangeValue=> ExcelData
    SET ColumnNames TO ExcelData.ColumnHeadersRow.ColumnNames
    Variables.CreateNewList List=> List
    LOOP FOREACH CurrentItem2 IN ExcelData
    LOOP FOREACH CurrentItem IN ExcelData.ColumnHeadersRow.ColumnNames
    IF StartsWith(CurrentItem, $'''Email''', False) THEN
    Display.ShowMessageDialog.ShowMessage Title: $'''ColumnNAme''' Message: CurrentItem Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False ButtonPressed=> ButtonPressed
    Variables.AddItemToList Item: CurrentItem List: List
    END
    END
    END
    SET EmailColumns TO List
    I'm able to get the column name that contains email but want to fetch their values and combine them with ;

  • CU16071609-1 Profile Picture
    6,255 Moderator on at

    @preettyy_312024 

     

    Your code appears to be in good shape. Only a minor syntax update is needed.

    Deenuji_0-1717668276839.png

     

    Deenuji_1-1717668297145.png

     

     


    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀

     

  • CU16071609-1 Profile Picture
    6,255 Moderator on at

    @preettyy_312024 

     

    Another point to note is that passing a list as the recipient address may result in an error.

     

    Instead of using a list, it might be more appropriate to create a set variable for the ToAddress field and concatenate each email with a semicolon during each iteration, particularly when your column contains email addresses.

     

    Green highlighted actions are updated from your previous code and remove list from the workflow.

     

     

    Deenuji_2-1717668734794.png

     

     

    Code:

    Outlook.Launch Instance=> OutlookInstance
    Excel.LaunchExcel.LaunchAndOpenUnderExistingProcess Path: $'''C:\\Boot\\Invoice_Details.xlsx''' Visible: False ReadOnly: False Instance=> ExcelInstance
    Excel.GetFirstFreeColumnRow Instance: ExcelInstance FirstFreeColumn=> FirstFreeColumn FirstFreeRow=> FirstFreeRow
    Excel.ReadFromExcel.ReadCells Instance: ExcelInstance StartColumn: $'''A''' StartRow: 1 EndColumn: FirstFreeColumn - 1 EndRow: FirstFreeRow - 1 ReadAsText: False FirstLineIsHeader: True RangeValue=> ExcelData
    SET ColumnNames TO ExcelData.ColumnHeadersRow.ColumnNames
    SET ToAddress TO $'''%''%'''
    LOOP FOREACH CurrentItem2 IN ExcelData
    LOOP FOREACH CurrentItem IN ExcelData.ColumnHeadersRow.ColumnNames
    IF StartsWith(CurrentItem, $'''Email''', False) THEN
    IF IsEmpty(ToAddress) THEN
    SET ToAddress TO CurrentItem2[CurrentItem]
    ELSE
    SET ToAddress TO $'''%ToAddress%;%CurrentItem2[CurrentItem]%'''
    END
    END
    END
    Outlook.SendEmailThroughOutlook.SendEmail Instance: OutlookInstance Account: $'''Deenu@onmicrosoft.com''' SendTo: ToAddress Subject: $'''test''' Body: $'''test''' IsBodyHtml: False IsDraft: False
    END

     

     


    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀

     

  • Preethi Ambati Profile Picture
    54 on at

    @Deenuji 
    Thanks for your help. But I want the I want the output like if there are 3 email columns in excel and for row one it has only 2 email then it should send email to only those two email id and for row 3 there are 3 emails then it should send email to all there like that

     

  • CU16071609-1 Profile Picture
    6,255 Moderator on at

    @preettyy_312024 

     

    I have already included those logic in my lates response. 

     

    But copy and paste the same here for your quicker reference.

    Refer the below updated logic.

    Deenuji_0-1717669773772.png

     

     

     

    Code:

    Outlook.Launch Instance=> OutlookInstance
    Excel.LaunchExcel.LaunchAndOpenUnderExistingProcess Path: $'''C:\\Boot\\Invoice_Details.xlsx''' Visible: False ReadOnly: False Instance=> ExcelInstance
    Excel.GetFirstFreeColumnRow Instance: ExcelInstance FirstFreeColumn=> FirstFreeColumn FirstFreeRow=> FirstFreeRow
    Excel.ReadFromExcel.ReadCells Instance: ExcelInstance StartColumn: $'''A''' StartRow: 1 EndColumn: FirstFreeColumn - 1 EndRow: FirstFreeRow - 1 ReadAsText: False FirstLineIsHeader: True RangeValue=> ExcelData
    SET ColumnNames TO ExcelData.ColumnHeadersRow.ColumnNames
    SET ToAddress TO $'''%''%'''
    LOOP FOREACH CurrentItem2 IN ExcelData
    LOOP FOREACH CurrentItem IN ExcelData.ColumnHeadersRow.ColumnNames
    IF StartsWith(CurrentItem, $'''Email''', False) THEN
    IF IsEmpty(ToAddress) THEN
    SET ToAddress TO CurrentItem2[CurrentItem]
    ELSE
    SET ToAddress TO $'''%ToAddress%;%CurrentItem2[CurrentItem]%'''
    END
    END
    END
    Outlook.SendEmailThroughOutlook.SendEmail Instance: OutlookInstance Account: $'''Deenu@onmicrosoft.com''' SendTo: ToAddress Subject: $'''test''' Body: $'''test''' IsBodyHtml: False IsDraft: False
    END

     


    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀

  • Preethi Ambati Profile Picture
    54 on at

    Thank you for your help this code is not giving the desired output. I want the output like if there are 3 email columns in excel and for row one it has only 2 email then it should send email to only those two email id and for row 3 there are 3 emails then it should send email to all there like that.

    preettyy_312024_0-1717671199438.png

     

     

  • CU16071609-1 Profile Picture
    6,255 Moderator on at

    @preettyy_312024 

     

    Please take the time to understand how it functions. Attempt to debug the code so that you can gain a better understanding as well.

     

    - Line 8: You will iterate through all the column names.
    - Line 9: We are verifying whether the current column name starts with "Email" or not.
    - Line 10: We are retrieving the email ID from the current row and checking whether it's empty or not.
    - Line 11: We are checking if the ToAddress variable is empty or not.
    - Line 12: If the ToAddress is empty, it will fetch and save your email ID in this variable.
    - Line 13: Else, if the ToAddress is not empty.
    - Line 14: It will add another email ID with a semicolon.

     

    Once loop of column name is completed then it will send email to Toaddress folks.

    Deenuji_2-1717671373615.png

     

     

    Code:

     

     

    Outlook.Launch Instance=> OutlookInstance
    Excel.LaunchExcel.LaunchAndOpenUnderExistingProcess Path: $'''C:\\Boot\\Invoice_Details.xlsx''' Visible: False ReadOnly: False Instance=> ExcelInstance
    Excel.GetFirstFreeColumnRow Instance: ExcelInstance FirstFreeColumn=> FirstFreeColumn FirstFreeRow=> FirstFreeRow
    Excel.ReadFromExcel.ReadCells Instance: ExcelInstance StartColumn: $'''A''' StartRow: 1 EndColumn: FirstFreeColumn - 1 EndRow: FirstFreeRow - 1 ReadAsText: False FirstLineIsHeader: True RangeValue=> ExcelData
    SET ColumnNames TO ExcelData.ColumnHeadersRow.ColumnNames
    SET ToAddress TO $'''%''%'''
    LOOP FOREACH CurrentItem2 IN ExcelData
     SET ToAddress TO $'''%''%'''
     LOOP FOREACH CurrentItem IN ExcelData.ColumnHeadersRow.ColumnNames
     IF StartsWith(CurrentItem, $'''Email''', False) THEN
     IF IsNotEmpty(CurrentItem2[CurrentItem]) THEN
     IF IsEmpty(ToAddress) THEN
     SET ToAddress TO CurrentItem2[CurrentItem]
     ELSE
     SET ToAddress TO $'''%ToAddress%;%CurrentItem2[CurrentItem]%'''
     END
     END
     END
     END
     Outlook.SendEmailThroughOutlook.SendEmail Instance: OutlookInstance Account: $'''Deenu@office365journey.onmicrosoft.com''' SendTo: ToAddress Subject: $'''test''' Body: $'''test''' IsBodyHtml: False IsDraft: False
    END

     

     

     

     

    Input Excel:

    Deenuji_1-1717671191009.png

     

     

    Output of first row iteration:

    Deenuji_0-1717671158480.png

     

     

    Second Row:

    Deenuji_4-1717671614793.png

     

     

    Output:

    Deenuji_3-1717671526300.png

     


    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀

  • Verified answer
    CU16071609-1 Profile Picture
    6,255 Moderator on at

    @preettyy_312024 

     

    Small validation and screenshot updated on the above response

  • Preethi Ambati Profile Picture
    54 on at

    Yes, but the variable is appending the email address of each row like in first row there are two email so it is send it to those 2 email id's but in 2nd iteration it is send to those in the first row and in 2nd row as well

  • CU16071609-1 Profile Picture
    6,255 Moderator on at

    @preettyy_312024 

     

    The code has already been modified in the previous responses to address the gap you mentioned.

     

    Line 8: Each Iteration again make Toaddress as empty

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

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 231 Super User 2026 Season 2

#2
David_MA Profile Picture

David_MA 217 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 170

Last 30 days Overall leaderboard