Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Replace font of one character in a string

I need to replace the font of one character in a text string in a range of
cells.
I can do this character by character by hand but I want to automate it.
If I use the replace function for one character than the font change is
applied to all characters in the cell while the font style (e.g. bold to
italic) is limited to the one specified character.
Does anyone know how to change the the font for only one character in such
a way that I can automate it. (e.g. All arial "1" need to be replaced by
windings "1 with a circle around it")
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Replace font of one character in a string

On Fri, 12 Jan 2007 16:35:02 -0800, PaulS
wrote:

I need to replace the font of one character in a text string in a range of
cells.
I can do this character by character by hand but I want to automate it.
If I use the replace function for one character than the font change is
applied to all characters in the cell while the font style (e.g. bold to
italic) is limited to the one specified character.
Does anyone know how to change the the font for only one character in such
a way that I can automate it. (e.g. All arial "1" need to be replaced by
windings "1 with a circle around it")


You can do it with a simple macro.

To enter the macro,

<alt-F11 opens the VB Editor.

Ensure your project is selected in the project explorer window, then
Insert/Module and paste the code below into the window that opens.

Read the notes in the code.

You can use it by selecting the area where you want this to occur, then
executing the macro.

===========================================
Option Explicit

Sub WingdingReplace()
Dim c As Range
Dim sWD1 As String
Dim i As Long

sWD1 = Chr(129) 'wingding encircled 1

'can only apply this to text strings, and not to strings that
'are the result of formulas.

'This does not work on formulas.
'If you want it to do so, you will have to also replace
' the formula with a plain text string.

For Each c In Selection
If c.HasFormula = False Then
c.Value = Replace(c.Text, "1", sWD1)
For i = 1 To Len(c.Text)
If Mid(c.Text, i, 1) = sWD1 Then
With c.Characters(Start:=i, Length:=1).Font
.Name = "Wingdings"
'this line may not be necessary but looked better on my screen
.Size = .Size + 2
End With
End If
Next i
End If
Next c

End Sub
=========================================
--ron
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Replace font of one character in a string

Or you can do a dirty way by hand. Copy the range and paste them in a new
sheet. And use the replace all function. And Copy and paste it back.

If you have formula included in the sheet.
Copy the whole sheet to a new one, replace all, and only copy the range and
paste it back.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Replace font of one character in a string

On Fri, 12 Jan 2007 17:41:00 -0800, jchen
wrote:

Or you can do a dirty way by hand. Copy the range and paste them in a new
sheet. And use the replace all function. And Copy and paste it back.

If you have formula included in the sheet.
Copy the whole sheet to a new one, replace all, and only copy the range and
paste it back.


Did you try your solution?

When I tried it, it did not change the font, but rather displayed a small box.


--ron
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel-Match 1st text character in a string to a known character? bushlite Excel Worksheet Functions 2 January 15th 07 06:36 PM
How replace a character in a string of characters? Chet Excel Programming 6 December 6th 06 01:54 AM
Replace character in string, not document KS[_2_] Excel Programming 3 October 26th 06 05:06 PM
Function to return Character Position of Xth character within a string Andibevan[_2_] Excel Programming 4 June 9th 05 03:24 PM
How do I replace * as a character in a string in Excel? nicolegt Excel Programming 1 January 21st 05 10:42 AM


All times are GMT +1. The time now is 09:24 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"