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

Hiding rows in excel

(0) ShareShare
ReportReport
Posted on by 61

Hello, 

 

I am trying to read rows from an excel, specific rows A15 to A17 and After reading I want to hide the rows . I am not able to hide the rows, any suggestions? I tried activating the individual cell eg A15 and then send keys  {Control}({9}) . In one instance it hid the row but the curly bracket } was visible on the next row. Can someone please help with this or suggest any other way to hide rows? Thank you. 

I have the same question (0)
  • WillSG Profile Picture
    352 Moderator on at

    Hi @Sh99  I hope you are doing well.

     

    If you have ONLY one Excel spreadsheet or the spreadsheet that you are working is in the foreground, you can use the Action “Run VBScript” and utilize the Visual Basic Script here below:


    Option Explicit

     

    Dim xlApp, xlBook, xlSheet

     

    ' Get a reference to the active Excel application

    Set xlApp = GetObject(, "Excel.Application")

     

    ' Get a reference to the active workbook

    Set xlBook = xlApp.ActiveWorkbook

     

    ' Set the active worksheet

    Set xlSheet = xlBook.ActiveSheet

     

    ' Hide rows A15 to A17

    xlSheet.Rows("15:17").EntireRow.Hidden = True

     

    ' Save the workbook (optional)

    xlBook.Save

     

    ' Release the object references

    Set xlSheet = Nothing

    Set xlBook = Nothing

    Set xlApp = Nothing

     

     

    Hope this helps,


    If I have addressed your inquiry successfully, kindly consider marking my response as the preferred solution. If you found my assistance helpful, a 'Thumbs Up' would be greatly appreciated.

     

    Additionally, I offer specialized consultancy and development services leveraging PAD. If you're interested in exploring these services further, feel free to DM me, and we can initiate a discussion.

     

    Kind regards,

     

    Will SG

    Managing Director & Automation Lead

    RAMS CR (Recruitment & Automation)

    LinkedIn Profile

  • Sh99 Profile Picture
    61 on at

    Hello, 

    Thank you for your response. The excel spreadsheet changes every time. I want to pass the excel spreadsheet path as a variable. 

  • Sh99 Profile Picture
    61 on at

    Also, I have multiple excel spreadsheets open.

  • Verified answer
    WillSG Profile Picture
    352 Moderator on at

    Understood @Sh99 , in that case you can use this code instead:

     

    Keep in mind that you need to have a variable or use the Set Variable Action to have the workbook name %WorkBookName% and check the file suffix as well, here it was defined as “.xlsx”, so adjust as needed.

     

    Option Explicit

     

    Dim xlApp, xlBook, xlSheet

     

    ' Get a reference to the active Excel application

    Set xlApp = GetObject(, "Excel.Application")

     

    ' Loop through all open workbooks

    For Each xlBook In xlApp.Workbooks

     

        If xlBook.Name = "%WorkBookName%" & ".xlsx" Then

            ' Set the active workbook

            Set xlBook = xlApp.Workbooks("%WorkBookName%" & ".xlsx")

            ' Set the active sheet

            Set xlSheet = xlBook.ActiveSheet

            ' Hide rows A15 to A17

            xlSheet.Rows("15:17").EntireRow.Hidden = True

            ' Save the workbook (optional)

            xlBook.Save

            ' Exit the loop since we found the workbook

            Exit For

        End If

    Next

     

    ' Release the object references

    Set xlSheet = Nothing

    Set xlBook = Nothing

    Set xlApp = Nothing



     

    Hope this helps,


    If I have addressed your inquiry successfully, kindly consider marking my response as the preferred solution. If you found my assistance helpful, a 'Thumbs Up' would be greatly appreciated.

     

    Additionally, if you have any questions, feel free to DM me, and we can initiate a discussion.

     

    Kind regards,

     

    Will SG

    Managing Director & Automation Lead

    RAMS CR (Recruitment & Automation)

    LinkedIn Profile

  • Sh99 Profile Picture
    61 on at

    Thank you so much for this solution. This is working fine.  Do you also have a vbscript that saves an excel (xlsx) doc into pdf? 

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 573

#2
Valantis Profile Picture

Valantis 407

#3
11manish Profile Picture

11manish 387

Last 30 days Overall leaderboard