![](/img/trans.png)
[英]How to automatically hide column based on row value, which is based on an if function from an opposing worksheet?
[英]How to hide row based on cell value in last column of worksheet?
我正在尝试创建一个宏,在该宏中搜索工作表的最后一列以寻找一个值,如果在单元格中找到该值,则该单元格的整个行都将被隐藏。 我还尝试为此使用动态范围,因为最后一列会更改。
With ws1
LastColumn = .Cells(1, Columns.Count).End(xlToLeft).Column
LastRow = .Cells(.Rows.Count, LastColumn).End(xlUp).Row
Set rDataRange = .Range(.Cells(2, LastColumn), .Cells(LastRow, LastColumn))
For Each rCell in RDataRange
If rCell.Value = "Yes" Then
rCell.EntireRow.Hidden = True
End If
Next rCell
End With
任何人都有一个想法,为什么这可能不起作用?
尝试:
Option Explicit
Sub test()
Dim LastColumn As Long, Lastrow As Long, i As Long
Dim str As String
With ThisWorkbook.Worksheets("Sheet1")
str = "Test"
LastColumn = .Cells(1, .Columns.Count).End(xlToLeft).Column
Lastrow = .Cells(.Rows.Count, LastColumn).End(xlUp).Row
For i = 1 To Lastrow
If .Cells(i, LastColumn).Value = str Then
.Rows(i).EntireRow.Hidden = True
End If
Next i
End With
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.