• hiding or making a row not visible based on other cell values

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » hiding or making a row not visible based on other cell values

    Author
    Topic
    #460945

    If I want to make rows 24, 25, & 28 not visible if cell b7+f7+j7=0 what is the best way to do this? I think I can incorporate into an existing macro but I don’t know how to write the code… I thought it would it be close to this but I keep getting a syntax error

    IF wsh.Range(“a24”).Value = “0” AND wsh.Range(“d24”).Value = “0” AND wsh.Range(“g24”).Value = “0” Then wsh.Range(“A24:A25”).EntireRow.Hidden = true AND wsh.Rows(28).Hidden = True

    Viewing 0 reply threads
    Author
    Replies
    • #1167401

      Your code uses different conditions from what you describe, but apart from that, you should be able to use

      Code:
      If wsh.Range("A24").Value = "0" And wsh.Range("D24").Value = "0" AND wsh.Range("G24").Value = "0" Then
        wsh.Range("A24:A25").EntireRow.Hidden = True
        wsh.Rows(28).Hidden = True
      End If
      • #1167404

        Thanks, Hans, it works perectly. How do you make the line break in the VBA window? When I hit enter to go to the next line, I get a compile error: Expected: expression

        Your code uses different conditions from what you describe, but apart from that, you should be able to use

        Code:
        If wsh.Range("A24").Value = "0" And wsh.Range("D24").Value = "0" AND wsh.Range("G24").Value = "0" Then
          wsh.Range("A24:A25").EntireRow.Hidden = True
          wsh.Rows(28).Hidden = True
        End If
        • #1167406

          If you want to break a line in Visual Basic code, type a space and an underscore at the place where you want the break, then press Enter. For example:

          Code:
          If wsh.Range("A24").Value = "0" And wsh.Range("D24").Value = "0" _
            And wsh.Range("G24").Value = "0" Then
          • #1168107

            Thank you – makes it easier to write & read (but not necessarily understand) the code.

            If you want to break a line in Visual Basic code, type a space and an underscore at the place where you want the break, then press Enter. For example:

            Code:
            If wsh.Range("A24").Value = "0" And wsh.Range("D24").Value = "0" _
              And wsh.Range("G24").Value = "0" Then
    Viewing 0 reply threads
    Reply To: hiding or making a row not visible based on other cell values

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: