Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.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/5/excel/25.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 如果D1>;O1_Vba_Excel - Fatal编程技术网

Vba 如果D1>;O1

Vba 如果D1>;O1,vba,excel,Vba,Excel,正如标题中所述,如果某一行的值高于另一列的值,我想知道如何隐藏该行 Dim ws as WorkSheet: Set ws = Sheets("Sheet1") Dim lr as Long lr = ws.Cells(Rows.Count, "E").End(xlUp).Row For each cell in ws.Range(ws.Cells(5, "E"), ws.Cells(lr, "E")) If cell = 0 Then cell.EntireRow.Hidd

正如标题中所述,如果某一行的值高于另一列的值,我想知道如何隐藏该行

Dim ws as WorkSheet: Set ws = Sheets("Sheet1")
Dim lr as Long
lr = ws.Cells(Rows.Count, "E").End(xlUp).Row

For each cell in ws.Range(ws.Cells(5, "E"), ws.Cells(lr, "E"))
   If cell = 0 Then
      cell.EntireRow.Hidden = True
   End If
Next cell
这是你们中的一位好心地为我的另一个问题提供的代码,用于隐藏值为0的行(我非常不擅长编程,考虑到我的职位,我需要做的大部分事情都是这样的,我想知道如何让它变得更简单。还有其他方法可以做,但这是一段代码,我至少需要了解一点,所以我想保留主框架,我不了解张贴在各个地方的其他解决方案,也不知道如何调整它们)

我知道一定有办法把de cell=0改成像cell所以,如果你们中有人能帮忙,那就太好了!

我还没有机会测试它,但像这样的东西

 Dim ws as WorkSheet: Set ws = Sheets("Sheet1")
    Dim lr as Long
    lr = ws.Cells(Rows.Count, "D").End(xlUp).Row

    For each cell in ws.Range(ws.Cells(5, "D"), ws.Cells(lr, "D"))
       If cell.value > ws.Cells(cell.row, "O").value Then
          cell.EntireRow.Hidden = True
       End If
    Next cell

检查D列,而不是E列,并将D列中的值与同一行上O列中的值进行比较

Dim i as long

with workSheets("Sheet1")

    'start at row 5 and work to the bottom row
    For i=5 to .Cells(.Rows.Count, "D").End(xlUp).Row
       'check the value in column D against the value in column O on the same row
       If .cells(i, "D").value > .cells(i, "O").value Then
          .cells(i, "D").EntireRow.Hidden = True
       End If
    Next i

end with

您也可以不使用
If
语句,只需在
For
循环中执行一行:
cell.EntireRow.Hidden=cell.value>ws.Cells(cell.row,“O”).value
如果你喜欢简洁的话。@jnevil是的。我会这么做。但是我想让它尽可能靠近OP的代码,这样他们就可以很容易地看到发生了什么变化。另外,这可能只是一个简化的例子(我认为在这个例子中不是这样的)OP可能想在if子句中做更多的事情。哦,是的。完全如此。我不建议用它更新答案,因为如果不在混合中引入布尔数学类型的东西,OP显然有点难以接受。但是对于未来的搜索者来说……非常感谢你的快速帮助!@Gravitate我知道这是一个个人的任务ion,这里没有发送消息的方法我想知道你从哪里学的vba和一些技巧?我是一个学生,必须大量使用excel文件,但遗憾的是我们没有关于它的课程。你可能还应该链接到原始问题: