Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-11-2020, 01:30 AM
JohnWilson JohnWilson is offline Case sensitivity not followed when using replace method. Windows 10 Case sensitivity not followed when using replace method. Office 2016
Programmer
 
Join Date: Nov 2008
Location: UK
Posts: 1,914
JohnWilson has a spectacular aura aboutJohnWilson has a spectacular aura about
Default

As I already said ...



You would need to account for each case e.g.

Replace BRIDGE with BRG (matchcase=True)
Replace Bridge with Brg (matchcase=True)
Replace bridge with brg (matchcase=True)
__________________
Microsoft PowerPoint MVP 2007-2023
Free Advanced PowerPoint Tips and Tutorials
Reply With Quote
  #2  
Old 10-11-2020, 02:32 AM
pushpi004 pushpi004 is offline Case sensitivity not followed when using replace method. Windows 10 Case sensitivity not followed when using replace method. Office 2016
Novice
Case sensitivity not followed when using replace method.
 
Join Date: Feb 2020
Posts: 21
pushpi004 is on a distinguished road
Default

Quote:
Originally Posted by JohnWilson View Post
As I already said ...

You would need to account for each case e.g.

Replace BRIDGE with BRG (matchcase=True)
Replace Bridge with Brg (matchcase=True)
Replace bridge with brg (matchcase=True)


Apparently, this isn't an efficient solution in my case..
Thanks anyway
Reply With Quote
  #3  
Old 10-14-2020, 06:21 AM
pushpi004 pushpi004 is offline Case sensitivity not followed when using replace method. Windows 10 Case sensitivity not followed when using replace method. Office 2016
Novice
Case sensitivity not followed when using replace method.
 
Join Date: Feb 2020
Posts: 21
pushpi004 is on a distinguished road
Default Solved: >Case sensitivity not followed when using replace method

Hi all..
Looks I have come across a solution to my problem. It is indeed using MatchCase as suggested by John, but in a slightly more developed logic. Nevertheless, it does the trick.

Sub DoReplace(tr As TextRange, findThis, replaceWith)
If InStr(1, tr.Text, findThis, vbTextCompare) > 0 Then 'is the word found at all?
'found at least one case form - just try to replace any case form found...
tr.Replace findWhat:=LCase(findThis), Replacewhat:=LCase(replaceWith), _
WholeWords:=True, MatchCase:=True
tr.Replace findWhat:=UCase(findThis), Replacewhat:=UCase(replaceWith), _
WholeWords:=True, MatchCase:=True
tr.Replace findWhat:=StrConv(findThis, vbProperCase), _
Replacewhat:=StrConv(replaceWith, vbProperCase), _
WholeWords:=True, MatchCase:=True
End If
End Sub

I hope it helps others as well.
Best of luck!
Cheers!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Case sensitivity not followed when using replace method. Title case macro gets a "type mismatch" error at the Instr method marceepoo Word VBA 1 03-05-2020 09:41 PM
Drawing Guides Sensitivity Setting? Slidemaker PowerPoint 2 05-18-2017 12:45 PM
Using wildcards in Find/Replace to change font/case angie450 Word 2 05-26-2016 11:09 AM
Case sensitivity not followed when using replace method. Find and replace with a macro, problem with letter case garcanrya Word VBA 2 01-10-2014 05:40 AM
Replace & case Jennifer Murphy Word 1 02-11-2013 03:26 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:34 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft