我在单列中有一个关键字列表。我需要将任何拼写错误的单词插入到相邻的单元格中,以便进行手动检查。仅拼写错误的单词,而不是整个单元格。

这个VBA脚本为我提供了大部分帮助,但我不知道如何复制拼写错误的单词。偏移(0,1)也会出错,但是偏移(1,0)可以工作。什么

现在,我会很高兴只复制第一个拼错的单词,但是如果它可以循环通过并将它们全部插入到它们右边的单元格中,那真是太好了。

使用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

最佳答案

试试这个小的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


例如:

vba - 将拼写错误的单词复制到相邻列-LMLPHP

注意:

在包含UDF()的单元格中打开自动换行。

关于vba - 将拼写错误的单词复制到相邻列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34228732/

10-11 03:58