0

I want to change "grape" to グレープ and below is the code I wrote,
but If I insert "ー" it is displayed as "?".

How can I solve this problem...??

Sub change_name()

    Dim c As Range

    For Each c In Selection
            c.Value = Replace(c.Value, "grape", "グレ?プ")       
    Next
End Sub
Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
tehoo
  • 81
  • 2
  • 9
  • Check if [this](https://stackoverflow.com/questions/51948424/using-multiple-language-english-chinese-japanese-in-vba) helps. – krobelusmeetsyndra Dec 26 '18 at 16:22
  • 2
    Check my response in this post https://stackoverflow.com/questions/53509921/vba-macro-to-search-a-text-string-and-replace-with-hyperlink-works-only-with-eng/53526940#53526940. Notice how it uses the `ChrW` unicode values for non-Latin characters. – Cindy Meister Dec 26 '18 at 16:42

1 Answers1

0

Try storing グレープ in a Named Range. Formulas > Name Manager > New >

"ReplaceText", Refers To: ="グレープ"

Then adjust your For Loop with:

c.Value = Replace(c.Value, "grape", Evaluate(Names("ReplaceText").Value))

Hope it helps.

Justyna MK
  • 3,523
  • 3
  • 11
  • 25
  • Thanks for your kind answer. Actually whole code I wrote is Sub change() Dim c As Range word1 = InputBox(Prompt:="Before", Title:="change") word2 = InputBox(Prompt:="After", Title:="change") For Each c In Selection c.Value = Replace(c.Value, word1, word2) Next End Sub Unfortunately the word I want to change to is random. I there any good way for this ? – tehoo Dec 26 '18 at 16:42
  • @tehoo you’d have to just keep adding names for each replacement you’d like to do – Marcucciboy2 Dec 26 '18 at 20:49