【发布时间】:2019-06-17 14:05:29
【问题描述】:
我正在过滤一个辅助单元格以定位 B 列中需要清除内容的单元格。一旦我过滤了已识别 B 列中需要清除内容的单元格的辅助单元格,我在清除该单元格中的内容时遇到问题。
除了我无法弄清楚如何仅从第一个可见单元格开始到最后一个可见单元格来清除可见单元格之外,我大致了解了这一点。我的问题是确定应用过滤器后第一个可见单元格的开始位置以及最后一个可见单元格的位置。
Sub Macro1()
'
' Macro1 Macro
Dim wb As Workbook
Dim ws As Worksheet
Dim FoundCell1 As Range
Set wb = ActiveWorkbook
Set ws = ActiveSheet
'This identifying the row of the last cell to filter on
Const WHAT_TO_FIND1 As String = "Tango"
Set FoundCell1 = ws.Range("AX:AX").Find(What:=WHAT_TO_FIND1)
'This is filtering on the helper cell to determine what cells need to be cleared.
ws.Range("$BA$8:$BA$" & FoundCell1.Row).AutoFilter Field:=1, Criteria1:= _
"Delete"
'This is where I'm having issues. I would like to replace B2 with a more dynamic code
'that finds the first visible cell after the filter is applied and start there.
'I think the xlUp solves the issue of finding the last visible cell but I am not sure
'if that is the best or correct method.
ws.Range("B2:B" & Rows.Count).End(xlUp).SpecialCells(xlCellTypeVisible).ClearContents
End Sub
【问题讨论】: