隐藏不包含值的行(负逻辑)

时间:2022-12-17 20:10:09

I have been working through this problem. I want to hide all cells that do not contain a text value in a cell. "C8" holds a value which can change as a function of a pull down menu.

我一直在解决这个问题。我想隐藏单元格中不包含文本值的所有单元格。 “C8”保存一个值,该值可以根据下拉菜单进行更改。

I want to leave the rows that contain the "C8" value, and hide all others. I can get it to work as long as I do not use a specific cell with a specific content (C8), when I add the variable of a certain cell value, the macro will not run.

我想留下包含“C8”值的行,并隐藏所有其他行。只要我不使用具有特定内容的特定单元格(C8),我就可以使它工作,当我添加某个单元格值的变量时,宏将不会运行。

Why won't it accept the specific cell content ?

为什么不接受特定的细胞内容?

Sub Hide_Based_upon_Selection()
Dim r As Long
For r = 9 To 37
If Range("C8").Value <> "PS" Then
    Rows(r).EntireRow.Hidden = True

    End If

If Range("C8").Value <> "VP" Then
    Rows(r).EntireRow.Hidden = True
    End If
           Next r

End Sub

1 个解决方案

#1


0  

Use this

用这个

Sub Hide_Based_upon_Selection()
Dim r As Long

For r = 9 To 37
    ActiveSheet.Rows(r).Hidden = ActiveSheet.Cells(r, "K") <> ActiveSheet.Range("C8")
Next r

End Sub

it will hide the row if the value in K is not equal to C8

如果K中的值不等于C8,它将隐藏该行

#1


0  

Use this

用这个

Sub Hide_Based_upon_Selection()
Dim r As Long

For r = 9 To 37
    ActiveSheet.Rows(r).Hidden = ActiveSheet.Cells(r, "K") <> ActiveSheet.Range("C8")
Next r

End Sub

it will hide the row if the value in K is not equal to C8

如果K中的值不等于C8,它将隐藏该行