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

Community site session details

Session Id : mLYHdnYpGx8vjOdeBF+9DW
Power Automate - Power Automate Desktop
Answered

Hiding rows in excel

Like (0) ShareShare
ReportReport
Posted on 31 Jan 2024 17:47:02 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)
  • Sh99 Profile Picture
    61 on 06 Feb 2024 at 12:58:11
    Re: Hiding rows in excel

    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? 

  • Verified answer
    WillSG Profile Picture
    352 Moderator on 31 Jan 2024 at 18:58:29
    Re: Hiding rows in excel

    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 31 Jan 2024 at 18:45:51
    Re: Hiding rows in excel

    Also, I have multiple excel spreadsheets open.

  • Sh99 Profile Picture
    61 on 31 Jan 2024 at 18:38:38
    Re: Hiding rows in excel

    Hello, 

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

  • WillSG Profile Picture
    352 Moderator on 31 Jan 2024 at 18:33:25
    Re: Hiding rows in excel

    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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

MS.Ragavendar – Community Spotlight

We are honored to recognize Ragavendar Swaminatha Subramanian as our September…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 736 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 396 Moderator

#3
Power Apps 1919 Profile Picture

Power Apps 1919 339

Last 30 days Overall leaderboard
Loading started
Loading complete