simple text replacer

andreymd87

New Member
Joined
Feb 7, 2021
Messages
4
Office Version
  1. 2019
Platform
  1. Windows
hi. i am trying to create a simple translator of text in cells.

i have one worksheet named "smeta" wich contains russian words. i need to create a macro that refers to another worksheet named (translator) and search those words there and replace them in same place in "smeta". the translator sheet is a table that contains russian words and next to them english translated words. so the question is. how to make this macro? i am very new to these things. thanks
 

Attachments

  • translator.png
    translator.png
    79.6 KB · Views: 15

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Hi adreymd87
The below code will do what you want
Put it in a module and in the cell where you want the answer put
Excel Formula:
=TRANSLATE(B6)
Change B6 to the word your trying to find
It will give a value error if the word does not exist

VBA Code:
Function TRANSLATE(SearchWord As String) As String
    TRANSLATE = ThisWorkbook.Sheets("TRANSLATOR").Range("A:A").Find(SearchWord).Offset(, 1).Value
End Function
 
Upvote 0
thanks. this works for a cell. but i wondered if the macro can search and replace all words in the sheet automatically. without typing the function
 
Upvote 0
Yeah it can, could you provide a snippit of what your sheet looks like
 
Upvote 0
1612799663672.png




i need all these russian words to be translated automatically in the same sheet, same cells when i run the macros.
 
Upvote 0
Ok, I have changed the code to work for your needs
Please change where it says Sheets("Name of sheet") to be the name of the sheet youve shown above
You can also add this code (RunTranslate) to a button on the devaloper tab


VBA Code:
Sub RunTranlate()
    For Each cell In ThisWorkbook.Sheets("Name of sheet").UsedRange.Cells
        If TRANSLATE(cell.Value) <> "Error" Then
            cell.Value = TRANSLATE(cell.Value)
        End If
    Next cell
End Sub


Function TRANSLATE(SearchWord As String) As String
    Dim FoundRng As Range
    Set FoundRng = ThisWorkbook.Sheets("TRANSLATOR").Range("A:A").Find(SearchWord)
    If FoundRng Is Nothing Then
        TRANSLATE = "Error"
    Else
        TRANSLATE = FoundRng.Offset(, 1).Value
    End If

End Function
 
Upvote 0
1612805999503.png

something happening but still wrong results. notice that the cells with #name? have formulas wich give also words. in the translator sheet is only one word added for testing. Артикул. wich is translated as articol. but as you can see here is the same name in cells instead of translated one.
 
Upvote 0
Hi,
Please check that the spelling is correct in each sheet and that there are no spaces after any of the words
 
Upvote 0

Forum statistics

Threads
1,214,383
Messages
6,119,198
Members
448,874
Latest member
Lancelots

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