我是第一次尝试使用宏的初学者。如果K列中的日期不等于今天的日期,我想删除工作表的整行。在代码之外有一些我无法解决的语法错误,我认为数据转储的列K没有被格式化为捕获我试图运行的代码的日期。
这是我到目前为止的代码。请温柔地尝试使用在线资源进行自学的人:)
Sub GetTodaysPopulation()
Dim MySheet As Worksheet, MyRange As Range
Dim LastRow As Long, LastCol As Long
Application.DisplayAlerts = False
Set MySheet = ThisWorkbook.Worksheets("TradeExData")
ThisWorkbook.Worksheets("TradeExData").Activate
With MySheet
LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
LastCol = .Range("A" & .Columns.Count).End(xlToLeft).Column
Set MyRange = .Range(.Cells(1, 1), .Cells(LastRow, LastCol))
End With
With MyRange
.AutoFilter([Field:=11], [Criteria1: <> Date])
.SpecialCells(xlCellTypeVisible).Offset(1, 0).Resize(.Rows.Count).Rows.Delete
End With
With MySheet
.AutoFilterMode = False
If .FilterMode = True Then
.ShowAllData
End If
End With
End Sub