我希望能够过滤A列(用vba删除不需要的内容)。
例子。
我希望过滤器有以下规格。
过滤器应该从字符之后开始 :
(对每个电池)
必须至少有10个字符(大写、小写、数字、特殊字符)。
https:/i.imgur.com3XiECI7.jpg。该单元(A:3, A:5, A:7, A:8)不符合标准。
所以我希望删除这些单元格。https:/i.imgur.com12N5k2O.jpg
我想删除每个单元格或行https:/i.imgur.comO3nIzDt.jpg
我有这样的代码来删除每一行empy。
来源于: Excel VBA - 删除空行 选项明确
Sub Sample()
Dim i As Long
Dim DelRange As Range
On Error GoTo Whoa
Application.ScreenUpdating = False
For i = 1 To 1000000
If Application.WorksheetFunction.CountA(Range("A" & i & ":" & "B" & i)) = 0 Then
If DelRange Is Nothing Then
Set DelRange = Range("A" & i & ":" & "B" & i)
Else
Set DelRange = Union(DelRange, Range("A" & i & ":" & "B" & i))
End If
End If
Next i
If Not DelRange Is Nothing Then DelRange.Delete shift:=xlUp
LetsContinue:
Application.ScreenUpdating = True
Exit Sub
Whoa:
MsgBox Err.Description
Resume LetsContinue
End Sub
你可以使用类似这样的代码。
Sub test1()
Dim OriginText, filterVal, startPosition
Dim ThereIs10Char As Boolean
Application.ScreenUpdating = False
For i = 1 To Cells.Rows.Count ' this will be slow ,you better use integer number ( rows count number) instead of Cells.Rows.Count
OriginText= Cells(i, "A").Value
startPosition = InStr(1, OriginText, ":")
filterVal = Mid(OriginText, startPosition + 1, Len(OriginText) - startPosition)
ThereIs10Char = False
If Len(filterVal >= 10) Then
ThereIs10Char = True
End If
'I dont understand your mean for empty lines
'you can use If condition for [while cells(i,"A").value="" Goto next i] or anything else
If ThereIs10Char = True Then
Rows(i).Delete Shift:=xlUp
i = i - 1
End If
Next
Application.ScreenUpdating = True
End Sub