[英]Highlight any cell without specific characters (lower case a-z) inside
I have some garbled characters (or, not garbled, but non-English characters such as A's with Scandinavian accents, etc), and I need to ferret them out of around 80,000 entries. 我有一些乱码(或者,不是乱码,但非英语字符,如带有斯堪的纳维亚口音的A等),我需要从大约80,000个条目中找出它们。
Can I write a formula to pick up and flag any cell that contains anything other than 我可以写一个公式来拿起和标志,含有比其他任何事情任何单元格
abcdefghijklmnopqrstuvwxyz?
ABCDEFGHIJKLMNOPQRSTUVWXYZ?
The following worked for me: 以下对我有用:
Option Explicit
Sub NonAscii()
Dim UsedCells As Range, _
TestCell As Range, _
Position As Long, _
StrLen As Long, _
CharCode As Long
Set UsedCells = ActiveSheet.Range("A1:A4271").CurrentRegion
For Each TestCell In UsedCells
StrLen = Len(TestCell.Value)
For Position = 1 To StrLen
CharCode = Asc(Mid(TestCell, Position, 1))
If CharCode < 97 Or CharCode > 122 Then
TestCell.Interior.ColorIndex = 36
Exit For
End If
Next Position
Next TestCell
End Sub
My tiny solution to this, would be using RegExp: 我对此的微小解决方案是使用RegExp:
Public Function demo(ByRef rngTarget As Range) As Boolean
Dim objRE As Object
Set objRE = CreateObject("vbscript.regexp")
With objRE
.Pattern = "[^a-z]"
.Global = True
'test will resolve true on any character other than a-z
demo = .Test(rngTarget.Value)
End With
Set objRE = nothing
End Function
Put this code into a module, then use it as a formula for a conditional format on the cells you want to test. 将此代码放入模块中,然后将其用作要测试的单元格上的条件格式的公式。
Formula would look as simple as this: =demo(A1)
公式看起来很简单:
=demo(A1)
If you need more information to this: MSDN 如果您需要更多信息: MSDN
You can of course use VBA to test all used cells: 您当然可以使用VBA来测试所有使用过的单元格:
'This code needs to be placed as a worksheet macro,
'or a worksheet needs to be specified for UsedRange
Public Sub TestAll()
Dim rngCell as Range
For Each rngCell In UsedRange.Cells
if demo(rngCell) then
rngCell.interior.color = RGB(125,125,125)
end if
Next rngCell
End Sub
You can use Conditional Formatting
for this which will highlight cells in-situ rather than needing to test each cell with a seprate formula or VBA
您可以使用
Conditional Formatting
,这将在原位突出显示单元格,而不是需要使用单独的公式或VBA
测试每个单元格
This formula validates that each character in A1
is lowercase az 此公式验证
A1
中的每个字符都是小写az
SUMPRODUCT(--((CODE(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1))>=97)),--(CODE(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1))<=122))<>LEN(A1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.