LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default Limits of Substitute and Replace functions

deutz wrote:

Auric__;1602931 Wrote:
deutz wrote:

I am using Excel 2003

I have a sheet that has in column A some long strings and I want a
quick way, preferably without looping, to replace some characters
with another character.

The problem I have run into is that when I use Replace in VBA it is
only applied to cells with no more than 1024 characters and so I
tried using Substitute but that crashes if there is more than 1271
characters in a cell so I don't know how to process these long
strings quickly.

I tried the following and hit the limits mentioned above:-


If the Replace function is in 2003, you can do this:
Selection.Value = Replace(Selection.Value, strOld, strNew)

In 2007 it works for me with a 32,768-character string. (I didn't test
it further than that.)

If the Replace function is *not* in 2003, you can use Split and Join:
Selection.Value = Join(Split(Selection.Value, strOld), strNew)

Also works for me with the same 32,768-character string. I *believe* it
should work as far back as Excel 2000.


Thanks for your suggestions Auric,

I substituted strOld and strNew with my strings and added code line
Range("A:A").Select just before your line of code

I then tried both methods but got a Type Mismatch error each time.


That's because they both expect a single string, i.e. a single cell. Try this
instead:
Dim cell As Range
For Each cell In Selection
cell.Value = Replace(cell.Value, strOld, strNew)
Next

--
Gene pool's running low on chlorine again.
 
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
Replace and Substitute Functions HLS[_2_] Excel Programming 0 September 21st 06 04:37 PM
wildcards with substitute of replace Jay Fincannon Excel Programming 5 September 16th 06 07:24 PM
Replace/substitute Viktor Ygdorff Excel Programming 0 July 17th 06 02:35 PM
Substitute/Replace Viktor Ygdorff Charts and Charting in Excel 0 July 17th 06 12:37 PM
Looking for a site with functions that substitute the ATP functions Franz Verga Excel Worksheet Functions 3 June 24th 06 04:30 AM


All times are GMT +1. The time now is 09:59 AM.

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"