Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VBA Excel搜索范围中的值并隐藏行(如果找到)_Excel_Vba - Fatal编程技术网

VBA Excel搜索范围中的值并隐藏行(如果找到)

VBA Excel搜索范围中的值并隐藏行(如果找到),excel,vba,Excel,Vba,我得到错误类型不匹配 我在这里做矩阵,如果一行包含“x”,那么代码应该保持一行可见。应隐藏没有“x”的行。变量hideEmptyRows从按钮触发 If (hideEmptyRows = True) Then For i = 8 To lastRow If Range(Cells(i, 3), Cells(i, lastColumn)).value = "x" Then cell.EntireRow.Hidden = T

我得到错误
类型不匹配

我在这里做矩阵,如果一行包含
“x”
,那么代码应该保持一行可见。应隐藏没有
“x”
的行。变量
hideEmptyRows
从按钮触发

If (hideEmptyRows = True) Then

        For i = 8 To lastRow

            If Range(Cells(i, 3), Cells(i, lastColumn)).value = "x" Then
                cell.EntireRow.Hidden = True
            End If

        Next i

    End Ifenter code here

类型为
Range
的对象没有
Value
这样的属性。您需要在整个范围内循环,以检查该范围内是否有任何单元格的值为“x”

您应该在代码中添加:

ifContains = false ' variable, which indicates if the value is present in current row
For j = 3 To lastColumn
    If Cells(i, j).Value = "x" Then
        ifContains = true
    End If
Next j

谢谢你,伙计!在你的提示下,我继续我的工作。