[英]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.