繁体   English   中英

Excel VBA - 如何查找和替换 30k 字符串上的单引号?

[英]Excel VBA - How can you find and replace single quotes on a 30k character string?

我正在尝试在 excel 中进行查找和替换,但 excel 没有找到任何东西,我认为这是由于字符数量过多,因为有些字符大约有 30,000 个,例如找到不要并用不要替换。

我想将此数据插入到 SQL 中,这就是为什么我试图删除所有单引号,查找和替换中有很多 Q 和 A,但我找不到任何适用于我的数据所具有的字符数的内容。

我在 VBA 方面很糟糕,所以除了下面不起作用的代码之外,我真的没有任何代码可以共享。

Selection.Replace What:="'", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False

感谢@Naresh 回答了这个问题。

Sub FindString()
Dim c As Range
Dim firstAddress As String
With Worksheets(1).Range("A1:a10")
    Set c = .Find("'", LookIn:=xlValues)
    If Not c Is Nothing Then
        firstAddress = c.Address
        Do
            c.Value = Replace(c.Value, "'", "quotechanged")
            Set c = .FindNext(c)
        Loop While Not c Is Nothing
    End If
End With
End Sub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM