gpt4 book ai didi

excel - 如何修改此代码以仅搜索可见的行和列

转载 作者:行者123 更新时间:2023-12-02 19:01:06 29 4
gpt4 key购买 nike

我有一个用户表单,允许用户选择与用户相关的行和列进行检查。我正在使用此代码,但它会搜索所有行和所有列,因此不会删除正确的行。谁能提出一个适用于行和列的解决方案来解决这个问题?谢谢。

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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com