我一直在寻找这个问题已经有一段时间了,但我对宏观调整并实施其他解决方案并没有足够的了解。
我正在使用Macro在一张纸上执行一定数量的操作。工作表的第一行包含标题,因此我需要从某些操作中排除第一行。
我将在下面粘贴我的代码,我知道这不是最好的方法(使用IF功能可能会更好)但这是我到现在为止的距离。有没有办法简单地排除宏中的整个标题行?或者只是在我填充T列的3个步骤中排除T1?
Sub TASKDUESTATUS()
'
' TASKDUESTATUS Macro
'
'
'Filter Completed and In Progress
ActiveSheet.UsedRange.AutoFilter Field:=21, Criteria1:= _
"=Completed", Operator:=xlOr, Criteria2:="=In Progress"
'Fill Column T with 3
Dim rX As Range
Set rX = Intersect(ActiveSheet.UsedRange, Range("T:T")).Cells.SpecialCells(xlCellTypeVisible)
rX.Value = "3"
'Filter Not Started
ActiveSheet.UsedRange.AutoFilter Field:=21, Criteria1:= _
"Not Started"
'Filter Date up till todays date with today INCLUDED
ActiveSheet.UsedRange.AutoFilter Field:=19, Criteria1:="<=" & Date
'Fill Column T with 2
Dim rX2 As Range
Set rX2 = Intersect(ActiveSheet.UsedRange, Range("T:T")).Cells.SpecialCells(xlCellTypeVisible)
rX2.Value = "2"
'Filter Not Started
ActiveSheet.UsedRange.AutoFilter Field:=21, Criteria1:= _
"Not Started"
'Filter date after todays date with today EXCLUDED
ActiveSheet.UsedRange.AutoFilter Field:=19, Criteria1:=">" & Date
'Fill Column T with 1
Dim rX3 As Range
Set rX3 = Intersect(ActiveSheet.UsedRange, Range("T:T")).Cells.SpecialCells(xlCellTypeVisible)
rX3.Value = "1"
'Add conditional formatting
Columns("T:T").Select
Selection.FormatConditions.AddIconSetCondition
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1)
.ReverseOrder = False
.ShowIconOnly = False
.IconSet = ActiveWorkbook.IconSets(xl3TrafficLights1)
End With
With Selection.FormatConditions(1).IconCriteria(2)
.Type = xlConditionValuePercent
.Value = 33
.Operator = 7
End With
With Selection.FormatConditions(1).IconCriteria(3)
.Type = xlConditionValuePercent
.Value = 67
.Operator = 7
End With
'Clear filters
ActiveSheet.UsedRange.AutoFilter Field:=21
ActiveSheet.UsedRange.AutoFilter Field:=19
End Sub
答案 0 :(得分:0)
添加i = Range("a1048576").End(xlUp).Row
以查找数据中填充最低的行,
并将("T:T")
更改为("T1:T" & i)
。
这在我的最后工作,请尝试让我知道。