如标题中所述,我想知道如果值大于另一列的值,则如何隐藏某一行。
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
答案 0 :(得分:4)
我还没有机会进行测试,但是像这样吗?
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
答案 1 :(得分:2)
遍历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