replace VBA not working consistantly

Oliver Dewar

Board Regular
Joined
Apr 17, 2011
Messages
201
Hi All.

Fairly simple one this. I think I'm dealing with a bug in excel 2007 - I'm doing this replace sequence in vba across a sheet with many instances of the character to replace, the sheet includes some cells with large strings of text.

Here's my code:

Code:
ActiveSheet.Cells.Replace What:="§§", Replacement:=Chr(10)

Some of the "§§" instances are replaced while others - especially those within the large text strings, are not.

Does anyone know of a sure fire way to do this replacement? Speed is preferable... but right now I'm just after 100% reliability.


edit*** oohh, just found out about Lookat:=xlWhole and the other settings... perhaps I need to stipulate those settings more concretly. Going to do more research but if you can put me out of my misery faster then please do!


Thanks All.

Oliver
 
Last edited:

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Ok, Ok so just when I was sure I'd found a bonafide excel bug it turns out that the problems was (as Hal put it) "Human error".

This is the code I just ran:

Cells.Replace What:="§§", Replacement:=Chr(10), LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

And it works. Seems that the changes you make in the manual search version is used again for the vba version - so you have to be specific in vba to reset.

Thanks for your moral support everyone ;)
 
Upvote 0
Spoke too soon. Still not reliable.

Thinking again that excel simply doesn't handle large find/replaces well.

Since the data is going into a csv file I'm thinking that I could open the csv file in notepad and do the find replace there from excel. Anyone know how to do this?
 
Upvote 0
Wow - that's scary... the notepad idea was bad.

Back to the start.

Can anyone give me a ironclad bit of code that will replace all instances of a charachter in a worksheet?

I'm beaten at the moment. Need an excel hero!
 
Upvote 0
Hi Guys. Forget this - when you hit a dead end enough times... you change vehicle! I'm going to use excel sheets to do what what I was going to do with csv files instead.
 
Upvote 0

Forum statistics

Threads
1,216,225
Messages
6,129,602
Members
449,520
Latest member
TBFrieds

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top