How to hide a row based on cell value (CodeEditor not VBA)

Anonymous
2023-03-20T16:44:51+00:00

Hello MS Community!

I am looking for a script in Code Script (not VBA) to hide a row based on a cell value. For example (refer to the below) IF Column A= "No", Hide Row 3. I will have a larger table associated with multiple "No"s, so being able to apply the logic to the larger sheet would be necessary. Thank you!

Microsoft 365 and Office | Excel | Other | MacOS

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. Anonymous
    2023-03-20T20:05:52+00:00

    Hi Nicole B!

    Try this code script

    Sub HideRows() Dim i As Integer For i = 1 To ActiveSheet.UsedRange.Rows.Count If Range("A" & i). Value = "No" Then Rows(i). Hidden = True End If Next i End Sub

    This code will loop through all of the rows in the worksheet and hide any rows where the value in column A is "No".

    Kindly let me know, if you require additional assistance, I will be glad to help further.

    Best Regards, Shakiru

    0 comments No comments
  2. Anonymous
    2023-03-20T20:27:44+00:00

    Hi Shakiru,

    Thanks for sending over this code. Unfortunately this is in VBA so it does not work with the version of excel Code Editor I have which is in Type Script. Any chance you know how to convert?

    Thanks,

    Nicole

    0 comments No comments
  3. Anonymous
    2023-03-20T20:36:29+00:00

    Hi Nicole B!

    Thank you for the feedback.

    Please try this:

    function hideRows() { const sheet = SpreadsheetApp.getActiveSheet(); const dataRange = sheet.getDataRange(); const values = dataRange.getValues();

    values.forEach((row, index) => { if (row[0] === "No") { // Change "No" to the cell value you want to trigger the hiding sheet.hideRows(index + 1); } }); }

    0 comments No comments
  4. Anonymous
    2023-03-20T20:47:24+00:00

    Hi Shakiru,

    Thanks for converting. I tried and got the below errors. Any chance you know how to troubleshoot?

    0 comments No comments
  5. Anonymous
    2023-03-21T08:57:56+00:00

    Hi Nicole B!

    Unfortunately, I don't have any further troubleshooting to offer.

    There are many knowledgeable users active on the forum and I hope that someone else can offer further insight into your issue.

    Kind Regards, Shakiru

    0 comments No comments