[英]Delete All Cells if not A-Z
我正在處理6列數據(AF)第2-4379行,並且大量單元格在過濾器列中顯示為“空白”,但不是真正的空格,因為它們似乎包含空格。 我希望找到一些vba示例,以查找包含ASCII值在65-90和97-122之間的范圍內的所有單元,如果這些值不包含在單元中,則將其完全清除。
這可能嗎? 我嘗試了一個子程序,該子程序檢查了“ IsText”,但始終收到與IsText行有關的“未定義子程序或函數”錯誤消息。
到目前為止,這是我嘗試過的:
Dim c As Range
Dim rng As Range
Set rng = Range("A2:F4379")
For Each c in rng
If Not IsText(c.Value) Then
c.ClearContents
End If
Next c
這應該從活動工作表中刪除大多數空格:
Option Explicit
Public Sub trimWhiteSpaces()
With ActiveSheet.UsedRange
.Replace What:=" ", Replacement:=vbNullString, LookAt:=xlWhole
.Replace What:=" ", Replacement:=vbNullString, LookAt:=xlWhole
.Replace What:=" ", Replacement:=vbNullString, LookAt:=xlWhole
.Replace What:=" ", Replacement:=vbNullString, LookAt:=xlWhole
.Replace What:=vbTab, Replacement:=vbNullString, LookAt:=xlWhole
.Replace What:=vbCrLf, Replacement:=vbNullString, LookAt:=xlWhole
.Replace What:=vbCr, Replacement:=vbNullString, LookAt:=xlWhole
.Replace What:=vbLf, Replacement:=vbNullString, LookAt:=xlWhole
.Replace What:=vbNewLine, Replacement:=vbNullString, LookAt:=xlWhole
.Replace What:=vbNullChar, Replacement:=vbNullString, LookAt:=xlWhole
.Replace What:=vbBack, Replacement:=vbNullString, LookAt:=xlWhole
.Replace What:=vbFormFeed, Replacement:=vbNullString, LookAt:=xlWhole
.Replace What:=vbVerticalTab, Replacement:=vbNullString, LookAt:=xlWhole
.Replace What:=vbObjectError, Replacement:=vbNullString, LookAt:=xlWhole
End With
End Sub
。
注意:
您的初始代碼有錯誤,因為您沒有將其包含在Sub()中
您可以使用類似於以下的結構來修復它:
Option Explicit
Public Sub testSub()
Dim c As Range
Dim rng As Range
Set rng = Range("A2:F4379")
For Each c In rng
If Not IsText(c.Value) Then
c.ClearContents
End If
Next
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.