Replacement Problem

YasserKhalil

Well-known Member
Joined
Jun 24, 2010
Messages
852
Hello

I have the following code that I use to replace some text with a nother

Code:
Sub Replacement()
    Dim LastRow As Long
    LastRow = Sheets("Conditions").Cells(Rows.Count, "A").End(xlUp).Row
      For x = 1 To LastRow
          Cells.Replace What:=Sheets("Conditions").Range("A" & x), Replacement:=Sheets("Conditions").Range("B" & x), _
          Lookat:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:= _
          False, ReplaceFormat:=False
      Next x
End Sub

If I want to replace for example (John Smith) with (Axel Smith)... There is no problem
But I found that the text (Johny Smith) is replaced with (Axely Smith) .. This is the problem.>>> I want to keep Johny as it is but replace just John
 
Excellent Mr. Rick
You are right and so am I
I tested it with the example above. It's perfect with English Words...
The problem is that I apply this code on Arabic Words.... And this is the problem now I discovered
What is the solution for it?
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Excellent work Mr. Rick
You are right and so am I

I tested the code with the example above and it worked very well ... I discovered the problem is in that I tried to apply the code on Arabic Language and this was the problem ...

The problem now with the language not the code!!!!
 
Upvote 0
Excellent work Mr. Rick
You are right and so am I

I tested the code with the example above and it worked very well ... I discovered the problem is in that I tried to apply the code on Arabic Language and this was the problem ...

The problem now with the language not the code!!!!
Unfortunately, I only know English, so I cannot help you with that part. However, maybe I can point you in the right direction. Consider these lines of code taken from my InStrExact function...
Rich (BB code):
  If CaseSensitive Then
    Str1 = SourceText
    Str2 = WordToFind
    Pattern = "[!A-Za-z0-9]"
    If AllowAccentedCharacters Then Pattern = Replace(Pattern, "!", "!" & UpperAndLowerAccents)
  Else
    Str1 = UCase(SourceText)
    Str2 = UCase(WordToFind)
    Pattern = "[!A-Z0-9]"
    If AllowAccentedCharacters Then Pattern = Replace(Pattern, "!", "!" & UpperAccentsOnly)
  End If
The two sections is where the letters of the alphabet are defined to the program (the other characters are required so do not remove the exclamation point or the digit range)... assuming the arabic alphabet has sequential ASCII/ANSI values, simply replace the "A" with the first upper case letter, the "Z" with the last upper case letter (do the same for the lower case "a" and lower case "z"... keep the dash between them where shown in my code) and I think the code might work for you.
 
Upvote 0
brother Yasser,
did you found any solution for Arabic words . I tried to change in patterns but it doesn't work.

thank you
 
Upvote 0

Forum statistics

Threads
1,215,339
Messages
6,124,375
Members
449,155
Latest member
ravioli44

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