Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.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
Excel 基于同一行的两列中的值隐藏行_Excel_Vba - Fatal编程技术网

Excel 基于同一行的两列中的值隐藏行

Excel 基于同一行的两列中的值隐藏行,excel,vba,Excel,Vba,我试图创建一个宏按钮,它分两步完成一件事。这是针对进度跟踪器的,如果任务在G列中标记为已完成,则需要隐藏该行 我已经完成了下面的命令,但是第二步是,如果c列“Name”中的值是隐藏的(基于第一个命令),那么我需要c列中的所有其他值,等于隐藏行的值,也隐藏。这样做的目的是通过删除C行中包含“已完成”任务的所有名称来返回所有正在进行的项目 '步骤1:(用于隐藏完成的行) “第二步:(非功能性想法) 试试这个: Sub HideCompletes() ' first find the last

我试图创建一个宏按钮,它分两步完成一件事。这是针对进度跟踪器的,如果任务在G列中标记为已完成,则需要隐藏该行

我已经完成了下面的命令,但是第二步是,如果c列“Name”中的值是隐藏的(基于第一个命令),那么我需要c列中的所有其他值,等于隐藏行的值,也隐藏。这样做的目的是通过删除C行中包含“已完成”任务的所有名称来返回所有正在进行的项目

'步骤1:(用于隐藏完成的行)

“第二步:(非功能性想法)

试试这个:

Sub HideCompletes()
    ' first find the last row in the spreadsheet that has data
    Dim lastrow As Long
    lastrow = ActiveSheet.Cells.SpecialCells(xlLastCell).Row

    ' now loop through the cells in G and hide them if they are completed
    For Each cell In ActiveSheet.Range("G5:G" & lastrow)
        If cell.Value = "Completed" Or cell.Value = "" Then
            cell.EntireRow.Hidden = True

            ' get the value from column C for that row
            Dim hiddenvalue As Variant
            hiddenvalue = ActiveSheet.Range("C" & cell.Row)

            ' now loop through the cells in C and hide them if they match our hidden value
            ' the value 0 will match an empty cell so we need to check both conditions
            For Each othercell In ActiveSheet.Range("C5:C" & lastrow)
                If othercell.Value <> "" And othercell.Value = hiddenvalue Then
                    othercell.EntireRow.Hidden = True

                End If
            Next othercell

        End If
    Next cell
End Sub
Sub HideCompletes()
'首先查找电子表格中包含数据的最后一行
最后一排一样长
lastrow=ActiveSheet.Cells.SpecialCells(xlLastCell.Row)
'现在在G中循环单元格,如果完成,则隐藏它们
对于ActiveSheet.Range(“G5:G”和lastrow)中的每个单元格
如果cell.Value=“已完成”或cell.Value=”“,则
cell.EntireRow.Hidden=True
'从列C中获取该行的值
作为变量的Dim hiddenvalue
hiddenvalue=ActiveSheet.Range(“C”和cell.Row)
'现在循环C中的单元格,如果它们与我们的隐藏值匹配,则隐藏它们
'值0将匹配一个空单元格,因此我们需要检查这两个条件
对于ActiveSheet.Range中的每个其他单元格(“C5:C”和lastrow)
如果othercell.Value“”和othercell.Value=hiddenvalue,则
othercell.EntireRow.Hidden=True
如果结束
下一个其他单元格
如果结束
下一个细胞
端接头

我想这是你想要的。如果G中的单元格为“已完成”或“”,则隐藏该行。然后,它循环遍历所有行,并隐藏在C列中与原来隐藏的行具有相同值的任何行。

一个
行高
=0的单元格已经隐藏,我想说。。。ActiveSheet.Range(“C5:C200”)中的cell.Value想要表示什么?你能用语言解释一下吗?我只是想在代码第一部分已经隐藏的单元格的基础上隐藏更多的单元格,如果这有意义的话。此处的行部分开始于引用隐藏单元格C列中的值。写入时,如果列c中行高不等于0的单元格值等于隐藏行的列c中的值,则隐藏行。如果单元格被隐藏,则整行也被隐藏。。。从它的角度来看。你能解释一下ActiveSheet.Range(“C5:C200”)中的
cell.Value是什么意思吗?抱歉,如果在回读时这让人困惑,我指的是基于单元格的行。我想说得更简单一些:如果非隐藏行的值(在C列)等于任何隐藏行的值(隐藏行的C列),那么就隐藏该行。步骤2的行与我在ActiveSheet.Range(“C5:C200”)中的cell.value上方的书面形式不同这是一个占位符,试图从C5开始调用该列中的所有单个单元格值,以与隐藏行的值进行比较。请给我一些时间来解释一下这是如何工作的,但它非常完美,非常有效。谢谢!
For Each cell In ActiveSheet.Range("G5:G200")
If cell.RowHeight = 0 And cell.Value In ActiveSheet.Range("C5:C200")
cell.EntireRow.Hidden = True
End If
Next cell
End Sub
Sub HideCompletes()
    ' first find the last row in the spreadsheet that has data
    Dim lastrow As Long
    lastrow = ActiveSheet.Cells.SpecialCells(xlLastCell).Row

    ' now loop through the cells in G and hide them if they are completed
    For Each cell In ActiveSheet.Range("G5:G" & lastrow)
        If cell.Value = "Completed" Or cell.Value = "" Then
            cell.EntireRow.Hidden = True

            ' get the value from column C for that row
            Dim hiddenvalue As Variant
            hiddenvalue = ActiveSheet.Range("C" & cell.Row)

            ' now loop through the cells in C and hide them if they match our hidden value
            ' the value 0 will match an empty cell so we need to check both conditions
            For Each othercell In ActiveSheet.Range("C5:C" & lastrow)
                If othercell.Value <> "" And othercell.Value = hiddenvalue Then
                    othercell.EntireRow.Hidden = True

                End If
            Next othercell

        End If
    Next cell
End Sub