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 / How to delete multiple...
Power Automate
Unanswered

How to delete multiple columns by using headers for desktop flow

(0) ShareShare
ReportReport
Posted on by 6
I have the same question (0)
  • Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    Delete from where exactly?

  • Srini007 Profile Picture
    3,483 Super User 2026 Season 1 on at

    Hi @Raghav_Power 

     

    If I understood you correctly You have an excel file with Headers, Now you need to Delete the Columns based on the Headers Name. If that so, then need to check, but we have Delete Column from Excel Worksheet which requires Index instead of Header Name

     

    But Next time, it's better you give some example / screenshot or some more explaination towards your issue

     

    If you find this reply helpful, please consider giving it a LIKE AND

    If this reply answers your question or solves your issue, please ACCEPT AS SOLUTION

     

    Thanks,

    Srini

  • kiran_g Profile Picture
    150 on at

    Hi @Srini007 

    Screenshot (46).png I want to delete columns 1, 3, and 5 by using Delete Column from Excel Worksheet.  How can we do it?

  • Raghav_Power Profile Picture
    6 on at

    Srini84,

     

    Thank you for your prompt response, 

    I'm New to power automate. I'm trying to filter columns and need to delete unnecessary columns in excel file, I tried with sql connections based on examples available in desktop flow but it's getting errors in connection string,

    Provider=Microsoft.ACE.OLEDB.12.0;Data Source=%NewVar%;Extended Properties="Excel 12.0 Xml;HDR=YES";

    NewVar is my ExcelPath

    I tried with
    Provider=Microsoft.ACE.OLEDB.8.0;Data Source=%NewVar%;Extended Properties="Excel 8.0 Xml;HDR=YES";

    I download and install Microsoft Access Database Engine 2010 Redistributable also,

    Please help me out this issue, give different methods to filter excel file

     

    Thnak You

    Raghav

     

     

  • Srini007 Profile Picture
    3,483 Super User 2026 Season 1 on at

    Hi @kiran_g 

     

    You can create your flow as below

     

    Srini84_1-1697701052333.png

     

    Below are the PAD Steps, copy and paste it to your PAD, change the path of your file

     

    Excel.LaunchExcel.LaunchAndOpenUnderExistingProcess Path: $'''C:\\Users\\S\\OneDrive \\Desktop\\Book123.xlsx''' Visible: True ReadOnly: False Instance=> ExcelInstance2
    Variables.CreateNewList List=> List
    Variables.AddItemToList Item: 1 List: List
    Variables.AddItemToList Item: 3 List: List
    Variables.AddItemToList Item: 5 List: List
    LOOP FOREACH CurrentItem IN List
     Text.ToNumber Text: CurrentItem Number=> TextAsNumber
     Excel.DeleteColumn Instance: ExcelInstance2 Column: TextAsNumber
    END
    

     

    If you find this reply helpful, please consider giving it a LIKE AND

    If this reply answers your question or solves your issue, please ACCEPT AS SOLUTION

     

    Thanks,

    Srini

     

  • Srini007 Profile Picture
    3,483 Super User 2026 Season 1 on at

    Hi @Raghav_Power 

     

    Can you Try without Variable, I mean to say HardCode the value and try? Also tell me what error you are getting

    One more check is that use Set Variable action and pass the value

     

    If you find this reply helpful, please consider giving it a LIKE AND

    If this reply answers your question or solves your issue, please ACCEPT AS SOLUTION

     

    Thanks,

    Srini

  • kiran_g Profile Picture
    150 on at

    It's removing the columns, but not in the way I wanted. I'd like to remove my first name, company name, and address.Screenshot (47).png

  • Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    The problem is because as soon as you delete the first column, every other column shifts to the left, and as such you should then delete column 2, and not 3 to remove the company name. Once you have deleted two columns, you need to delete column 3 instead of 5 to remove the address.

     

    A better approach would be to add the column numbers in the reverse order into the list. You would start deleting at column 5 first, which wouldn't cause columns 1 and 3 to move anywhere.

     

    So, essentially, try this:

     

    Excel.LaunchExcel.LaunchAndOpenUnderExistingProcess Path: $'''C:\\RPA\\Test.xlsx''' Visible: True ReadOnly: False Instance=> ExcelInstance
    Variables.CreateNewList List=> List
    Variables.AddItemToList Item: 5 List: List
    Variables.AddItemToList Item: 3 List: List
    Variables.AddItemToList Item: 1 List: List
    LOOP FOREACH CurrentItem IN List
     Text.ToNumber Text: CurrentItem Number=> TextAsNumber
     Excel.DeleteColumn Instance: ExcelInstance Column: TextAsNumber
    END

     

     

    Please remember to change the path to your file in the Launch Excel action.

    -------------------------------------------------------------------------
    If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.

    I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.

  • Srini007 Profile Picture
    3,483 Super User 2026 Season 1 on at

    Hi @kiran_g 

     

    So, you don't want to remove entire column, but only you need to remove the Headers of First Name, Company Name only then no need to column Number to pass then you can pass First Name, Company Name etc to Find and replace action

     

    Revised steps as below

    Srini84_0-1697708515796.png

     

    Steps to reproduce in PAD

     

     

    Excel.LaunchExcel.LaunchAndOpenUnderExistingProcess Path: $'''C:\\Users\\S\\OneDrive\\Desktop\\Book123.xlsx''' Visible: True ReadOnly: False Instance=> ExcelInstance2
    Variables.CreateNewList List=> List
    Variables.AddItemToList Item: $'''First Name''' List: List
    Variables.AddItemToList Item: $'''Company Name''' List: List
    Variables.AddItemToList Item: $'''Address''' List: List
    LOOP FOREACH CurrentItem IN List
     Excel.FindAndReplace.FindAndReplaceSingle Instance: ExcelInstance2 TextToFind: CurrentItem TextToReplaceWith: NewInput MatchCase: False MatchEntireCellContents: False SearchBy: Excel.SearchOrder.Columns FoundColumnIndex=> FoundColumnIndex FoundRowIndex=> FoundRowIndex
    END

     

     

    Make sure you change the file path and also create a variable NewInput as string and don't assign a value, so that it help to replace a null value

     

    If you find this reply helpful, please consider giving it a LIKE AND

    If this reply answers your question or solves your issue, please ACCEPT AS SOLUTION

     

    Thanks,

    Srini

  • kiran_g Profile Picture
    150 on at

    Thanks. It works when it's in reverse order and also I'm trying to run by VB script but it's not working. If you know it'll be helpful to make the process fast. I have used the below script to run 

    Sub DeleteColumnsByHeaderName()
        Dim HeaderNames() As Variant
        Dim HeaderName As Variant
        Dim LastColumn As Long
        Dim ColumnIndex As Long
        Dim Found As Boolean
     
    set xlApp = CreateObject("Excel.Application")
    set xlWbk = xlApp.Workbooks.Open(%f_Path%)
    set xlWksht = xlWbk.Worksheets("RPA")
        xlApp.Visible = true
     
    HeaderNames = Array("First Name", "Last Name", "Company Name")
     
        ' Find the last column in the active sheet
        LastColumn = Cells(1, Columns.Count).End(xlToLeft).Column
     
        ' Loop through the header names
        For Each HeaderName In HeaderNames
            Found = False
     
            ' Search for the header name in the first row
            For ColumnIndex = 1 To LastColumn
                If Cells(1, ColumnIndex).Value = HeaderName Then
                    Found = True
                    ' Delete the entire column if the header name is found
                    Columns(ColumnIndex).Delete
                    Exit For
                End If
            Next ColumnIndex
     
            ' Display a message if the header name was not found
            If Not Found Then
                MsgBox "Header '" & HeaderName & "' not found.", vbExclamation
            End If
        Next HeaderName
    End Sub

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 Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Valantis Profile Picture

Valantis 463

#1
Valantis Profile Picture

Valantis 463

#3
11manish Profile Picture

11manish 264

Last 30 days Overall leaderboard