删除所有单元格,如果不是AZ
我正在通过6列数据(AF)行2-4379和大量的单元格在filter列中显示为“空白”,但不是真正的空白,因为它们似乎包含空格。 我希望find一些vba的例子来find一个范围内包含65-90和97-122之间的ASCII值的所有单元格,如果这些值不包含在一个单元格内,然后完全清除它。
这可能吗? 我已经尝试了检查“IsText”,但不断收到“子或function未定义”错误消息与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
- VBA Excel:如何将不同types的parameter passing给函数(或将Int / String转换为范围)?
- Python xlsxwriter,添加格式到单元格,因为我写他们而不是批量