我在一个列中有一个关键字列表。我需要将任何拼写错误的单词插入相邻单元格以进行人工审核。只有拼写错误的单词,而不是整个单元格。
这个VBA脚本让我大部分都在那里,但我无法弄清楚如何复制拼写错误的单词。此外,偏移(0,1)错误输出,但偏移(1,0)有效。 WTH?
现在我对第一个拼写错误的单词感到满意,但是如果它可以循环并将它们全部插入到它们右边的单元格中,那么这很棒。
使用Excel VBA Delete Row If Mispelled Word
中的VBA代码Sub DeleteMispelledCells()
Dim lRow As Long, cl As Range
With ActiveSheet
For lRow = .UsedRange.Rows.Count To 1 Step -1
For Each cl In .Rows(lRow)
If Not IsEmpty(cl) Then
If Not Application.CheckSpelling(Word:=cl.Text)
cl.Copy
cl.Offset(1, 0).Insert 'The Offset(0, 1) throws an error. Why?
Application.CutCopyMode = False
Exit For
End If
End If
Next cl
Next lRow
End With
End Sub
答案 0 :(得分:0)
试试这个小 UDF():
Public Function CheckPhrase(r As Range) As String
Dim MyText As String, ary, a
MyText = LCase(r(1).Text)
MyText = FixUp(MyText)
ary = Split(MyText, " ")
Dim oxlAp As Object
Set oxlAp = CreateObject("Excel.Application")
CheckPhrase = ""
For Each a In ary
If Not oxlAp.CheckSpelling(a) Then
CheckPhrase = CheckPhrase & vbCrLf & a
End If
Next a
oxlAp.Quit
Set oxlAp = Nothing
End Function
Public Function FixUp(sin As String) As String
Dim t As String, ary, a
t = sin
ary = Array(",", ".", ";", ":""'")
For Each a In ary
t = Replace(t, a, "")
Next a
FixUp = t
End Function
例如:
<强> 注意:的强>
在包含 UDF()。
的单元格中打开文本换行