谁能帮我用这个宏在一列中创建多个小计?任何帮助都会很棒。我在 Y 列中有一组数字。从第 16 行开始。数据每三行列出一次,直到该部分结束,然后有大约 30 行的间隙,然后又出现了。我想创建一个宏来计算每个部分中有多少个 >45 的数字。将总共 2 行放在每个部分的最后一个数据点下方。在同一行的 X 列中,编号>45
Sub Sample()
Dim result As Long, firstrow As Long, lastrow As Long
Dim ws As Worksheet
Dim rng As Range
Set ws = ThisWorkbook.Sheets("Sheet1")
With ws
'~~> Find Lastrow in Col Y
lastrow = .Range("Y" & .Rows.Count).End(xlUp).Row
'~~> Set First row
firstrow = 16
'~~> Set your range
Set rng = .Range("Y" & firstrow & ":Y" & lastrow)
'~~> Put relevant values
.Range("x" & lastrow + 2).Value = "Total>45"
.Range("y" & lastrow + 2).Value = _
Application.WorksheetFunction.CountIf(rng, ">45")
End With
End Sub