简体   繁体   中英

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

I am trying to do a find and replace in excel but excel is not finding anything and i think it is due to the amount of characters as there are some that have around 30,000 and for example find Don't and replace with Dont.

I want to insert this data into SQL and this is why i am trying to remove all the single quotes, there are many Q and A's on find and replace but i cant find anything that works for the amount of characters my data has.

I am terrible at VBA and so i don't really have any code to share except the below which doesn't work.

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

Thanks to @Naresh who answered this.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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