LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default VBA Find and Replace isn't working on apostrophe within cell value

Hi,

I have an Excel 2007 app that writes data to SQL Server. Whenever I
have an apostrophe in a word within a cell, I replace it with double
quotes to prevent it from hosing my query. For some reason, in some
cells the find and replace code doesn't work. I entered the word
"that's" into each cell in a selected range to test the following
code:

Selection.Replace What:="'", Replacement:="''", LookAt:=xlPart, _
SearchOrder:=xlByRows

Most instances of the apostrophe are replaced correctly, but some are
unchanged. I modified the code to look for ascii characters with the
same result:

Selection.Replace What:=chr(39), Replacement:=chr(34), LookAt:=xlPart,
_
SearchOrder:=xlByRows

When I manually select the range and invoke the Find and Replace
command through the Excel UI, all instances of the apostrophe get
replaced.

How can I force the code to replace the apostrophes?

TIA,
-Jon

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Choose format while Find & Replace not working Ghitorni Excel Discussion (Misc queries) 0 February 22nd 10 10:29 AM
Find and Replace function not working wt.pm Excel Discussion (Misc queries) 2 April 14th 09 05:16 PM
Find/Replace Unshown Apostrophe ajvasel Excel Programming 2 March 6th 07 05:47 PM
My Find and Replace function in Excel is not working? BPeach Excel Worksheet Functions 2 December 20th 06 11:27 PM
FIND and REPLACE ' apostrophe James T Excel Discussion (Misc queries) 3 June 9th 06 06:55 AM


All times are GMT +1. The time now is 02:11 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"