我希望能够过滤A列(使用vba删除我不需要的内容)
示例:
我希望使用以下规格的过滤器:
: (每个单元格)https://i.imgur.com/3XiECI7.jpg这个细胞(A:3,A:5,A:7,A:8)不尊重标准
所以我想删除这个细胞。https://i.imgur.com/12N5k2O.jpg
我希望删除每个空单元格或行https://i.imgur.com/O3nIzDt.jpg
我有删除每个空行的代码
来源:Excel VBA - Delete empty rows选项显式
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发布于 2020-05-16 08:01:13
您可能考虑过了。我将暂时忽略问题中的VBA部分。您可以使用Excel的内置过滤功能过滤字符串:
A1设置为“strings”)并过滤该列。
:??????????。它将匹配包含一个:的任何值,后面跟着10个额外的字符。发布于 2020-05-15 05:45:36
您可以使用这样的代码:
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 Subhttps://stackoverflow.com/questions/61812041
复制相似问题