Find & replace string in text
Be, The following code will work with the active cell. You will need to put
it in a standard module (not the worksheet module). To create a standard
module, with the spreadsheet on the screen, press Alt-F11 to go to the code
editor. Click Insert from the menubar, then click on Module. Copy this
code and put it in there. I would assign a shortcut key to it. To do this,
press Alt-F11 to return to the spreadsheet. Click Tools on the menubar,
then Macro, then Macros. Select PutChr from the list and click Options.
Type a letter into the little box that says Shortcut Key. z is a good key
to use. Click OK, then click Cancel. Save the file. Now you can use the
shortcut key, like Crl-z to call the subroutine. The userform would be more
complicated, because I don't know how familiar you are with userforms. If
you still want the userform code, post back. James
Sub PutChr()
Dim r As Range
Set r = ActiveCell
Dim s As String
s = r.Value
s = Replace(s, "[", ChrW(780))
s = Replace(s, "]", ChrW(768))
s = Replace(s, "<", ChrW(772))
s = Replace(s, "", ChrW(769))
s = Replace(s, "~", ChrW(776))
r.Value = s
End Sub
"BeSmart" wrote in message
...
Don't worry - I worked through the character codes near 780 until I found
the
ones I want to use.
I now have another problem - I want to apply the same function to a user
form textbox - but it's clashing because originally we created a
worksheet_change which doesn't work during the initiation and reporting
from
a userform.
Can any help me to adapt the following code to apply to the current active
cell or to apply when the userform textbox is being filled in?
Private Sub Worksheet_Change(ByVal Target As Range)
Set r = Target
Dim s As String
s = r.Value
s = Replace(s, "[", ChrW(780))
s = Replace(s, "]", ChrW(768))
s = Replace(s, "<", ChrW(772))
s = Replace(s, "", ChrW(769))
s = Replace(s, "~", ChrW(776))
Application.EnableEvents = False
r.Value = s
Application.EnableEvents = True
End Sub
--
Thank for your help
BeSmart
"BeSmart" wrote:
Thanks James - That worked perfectly.
FYI - I'm trying to type a database of pinyin (a version of
chinese/english)
which needs these tones ontop of vowels, but I want to apply the tones to
a
modern looking font.
One last question - The character code you used "ChrW(780)" is different
to
the one I found under insert / symbols "030C" - where do I find the
correct
character code numbers?
--
Thank for your help
BeSmart
"Zone" wrote:
I think this gives the character you want. If the whole cell is
formatted
for Tahoma, changing Gary"s line like this should replace x with it.
s = Replace(s, "x", ChrW(780))
It is a weird little character, though. It doesn't seem to want to
appear
unless the character to the left of it works with this kind of
character.
HTH, James
"BeSmart" wrote in message
...
Thanks Gary - That worked brilliantly
One more question please...
If I want to replace the normal letter with a symbol (e.g. character
code
030C which is a combining diacritical mark under the tahoma font)
what do
I
need to change in the code?
--
Thank for your help
BeSmart
|