我有一个用户窗体,该窗体允许用户选择与用户相关的行和列。我正在使用此代码,但是它搜索所有行和所有列,因此不会删除正确的行。谁能提出解决此问题的解决方案,使其适用于行和列?谢谢。
Dim RowToTest As Long
Dim MySheet As Worksheet
Dim ProjectedDate As Date
Dim ColToTest As Long
Dim TempKeep As Integer
TempKeep = 0
ProjectedDate = Date + 60
For Each MySheet In ThisWorkbook.Sheets
For RowToTest = MySheet.Cells(Rows.Count, 1).End(xlUp).Row To 2 Step -1
For ColToTest = MySheet.Cells(2, Columns.Count).End(xlToLeft).Column To 15 Step -1
With MySheet.Cells(RowToTest, ColToTest)
If IsDate(MySheet.Cells(RowToTest, ColToTest).Value) Then
If .Value < ProjectedDate Then
TempKeep = 1
End If
End If
End With
Next ColToTest
If TempKeep = 0 Then
MySheet.Rows(RowToTest).EntireRow.Delete
End If
TempKeep = 0
Next RowToTest
Next
最佳答案
您可以通过其.Rows
和.Columns
属性检查单元格是否被隐藏,如下所示:
If CelToCheck.Rows.Hidden or CelToCheck.Columns.Hidden Then
'Your code if hidden
Else
'Code if not hidden
End if
在您的情况下,CelToCheck将是
MySheet.Cells(RowToTest, ColToTest)
另外,您可以设置范围变量,并仅通过
For each CL in RangeVariable.SpecialCells(xlCellTypeVisible)
'Your code
Next CL
关于excel - 如何修改此代码以仅搜索可见的行和列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56302703/