Private Sub text()
Dim jcbh As String
Dim rowsnum As Long
Dim lRow As Long
Dim lastRow As Long
Dim i As Long, j As Long, k As Long
Dim FR As Range
Dim RNG As Range
jcbh = "22-0801"
rowsnum = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
ActiveSheet.Range("A1:Z" & rowsnum).AutoFilter Field:=1, Criteria1:="*" & jcbh & "*"
'Set FR = ActiveSheet.UsedRange.SpecialCells(xlCellTypeVisible, 23) '方法一,选中筛选数据
'Set filterRange = ActiveSheet.Range("A1").CurrentRegion '方法二,选中筛选数据
'
'fr.Copy ThisWorkbook.Sheets("SHEET2").Range("A1") '将筛选出的数据复制到SHEET2中,用来验证
'lastrow = Application.WorksheetFunction.Subtotal(3, Range("A1:A" & rowsnum))'方法一,统计筛选后可见数据行数
'lRow = ActiveSheet.Range("A1:a" & rowsnum).SpecialCells(xlCellTypeVisible).Cells.Count '方法二,统计筛选后可见数据行数
'用于统计N列或O列有无日期的行数
k = 0 '初始化K值
ke = 0
For i = 2 To rowsnum '标题是第一行,从第二行开始
'经过筛选后,判断行是否显示,如果是显示的,则获取其行号,并计算显示行的N和O列之和是否为0,如果是0则是未配送的,进行计数
If Not ActiveSheet.Rows(i).Hidden Then
j = ActiveSheet.Cells(i, "A").Row
On Error Resume Next '如果存在文本,会有类型匹配出错提示,忽略提示继续执行
If ActiveSheet.Cells(j, "N").Value + ActiveSheet.Cells(j, "O").Value = 0 Or _
IsError(ActiveSheet.Cells(j, "N").Value + ActiveSheet.Cells(j, "O").Value) Then
k = k + 1
End If
On Error GoTo 0 '恢复
End If
Next i
ActiveSheet.ShowAllData
MsgBox k
End Sub
VBA 对于筛选的一些操作
最新推荐文章于 2024-08-16 16:58:11 发布