Good evening,
I'm quite new with using Excel formulas and anything beyond the basics. However, I'm in need of some help quite urgently.
I was wondering if it was possible to "Replace All" but have conditions.
For example, if I want to replace all instances over multiple cells all that ' (apostrophe) and replace them with ` (French e accent) except for when the ' (apostrophe) is needed to be spelled correctly (EX: I'm, we're, they're, don't ...).
What would that formula be?
Example:
Cell 1 = You're 'going' home
Cell 2 = Okay, you'll see 'later'
I would want to keep the ' that is in "You're" and "you'll", but I want to replace the ' around "going" and "later" with ` instead.
Can someone please help?
Much appreciated,
Lanhoj
Hi Lanhoi,
Welcome to the forum.
The main challenge here will be to figure out the rules that Excel should apply. The single quote can appear
at the beginning of a word: ('ere we go, 'fraid of nothing, 'fess up)
at the end of a word (several companies' products, the ladies' room)
or sandwiched between two letters (You're next)
The only safe rule would be to keep the sandwiched apostrophe, but as for the others: can you think of a rule to apply?
teylyn
Microsoft MVP - Excel
At Excelforum, you can say "Thank you!" by clicking theicon below the post.
Avoid pie charts with more than two data points. Why? See here (pdf, 559 kb). The only acceptable pie chart is here.
The only rule I really need would be to keep the apostrophe when it's needed as part of a correctly spelled word. And when it's not, to replace the apostrophe with the French e accent.
" You're in the 'car's' garage " for example, should be:
" You're in the `car's` garage " with the apostrophe`s around " 'car's' " changing to the French e accent.
Humans know what words are spelled correctly and which are not when taking punctuation into account because we've spent years figuring it all out. Excel will only know exactly what you teach it within the macro. It will only obey instructions.
You have to fathom a logic that we can employ in the macro other than just "because we know it's right". Nobody's going to write a macro for you that individually deals with every possible use of an apostrophe for every possible word and position.
If you reread post #3, you've demonstrated only that a human knows it's right.
If you can define a set of exacting rules that generically explain the steps a macro should follow to determine whether an apostrophe should be replaced or not, we can help turn that reasoning into code for you.
Last edited by JBeaucaire; 02-04-2010 at 08:47 PM.
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
“None of us is as good as all of us” - Ray Kroc
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
When an apostrophe is used in one of the following ways, it should remain unchanged:
're
've
'll
't
's
'm
If an apostrophe is used anywhere else, it should be replaced with an `
Would those rules be okay?
How would that be turned to code?
Erhmm. Well, some do, some don't. Lately it looks like most don'tHumans know what words are spelled correctly and which are not![]()
teylyn
Microsoft MVP - Excel
At Excelforum, you can say "Thank you!" by clicking theicon below the post.
Avoid pie charts with more than two data points. Why? See here (pdf, 559 kb). The only acceptable pie chart is here.
How about a UDF?
Code:Function Grave(ByVal s As String) As String Static av As Variant Dim v As Variant Dim iPos As Long If IsEmpty(av) Then av = Array("'re", "'ve", "'ll", "'t", "'s", "'m") iPos = InStr(iPos + 1, s, "'") Do While iPos For Each v In av If InStr(iPos, s, v) = iPos Then Mid(s, iPos) = Chr(143) Exit For End If Next v iPos = InStr(iPos + 1, s, "'") Loop Grave = Replace(Replace(s, "'", "`"), Chr(143), "'") End Function
Last edited by shg; 02-05-2010 at 02:42 PM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks