Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Replace Font within Cell

You could use a macro that finds the cell with the word and then italices the
characters in that word in that cell.

If you want to try:

Option Explicit
Sub testme()

Dim myRng As Range
Dim FoundCell As Range
Dim FirstAddress As String
Dim myWords As Variant
Dim wCtr As Long
Dim wks As Worksheet
Dim StartPos As Long

Set wks = Worksheets("sheet1")

'change this to the list of words to find
myWords = Array("qwer", "asdf")

With wks
'change this to the range that should be inspected
Set myRng = .Range("L:L")

With myRng
For wCtr = LBound(myWords) To UBound(myWords)
FirstAddress = ""

With .Cells
Set FoundCell = .Find(What:=myWords(wCtr), _
after:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)

If FoundCell Is Nothing Then
'do nothing, it wasn't found
MsgBox myWords(wCtr) & " wasn't found!"
Else
FirstAddress = FoundCell.Address
Do
StartPos = InStr(1, FoundCell.Value, _
myWords(wCtr), vbTextCompare)
If StartPos = 0 Then
'this shouldn't happen,
'since the .find worked ok
Else
With FoundCell.Characters _
(Start:=StartPos, _
Length:=Len(myWords(wCtr))).Font
.FontStyle = "Italic"
End With

'look for the next one
Set FoundCell = .FindNext(after:=FoundCell)

If FirstAddress = FoundCell.Address Then
'at the first address
Exit Do
End If
End If
Loop
End If
End With
Next wCtr
End With
End With

End Sub

If you're new to macros:

Debra Dalgleish has some notes how to implement macros he
http://www.contextures.com/xlvba01.html

David McRitchie has an intro to macros:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Ron de Bruin's intro to macros:
http://www.rondebruin.nl/code.htm

(General, Regular and Standard modules all describe the same thing.)

Stephanie M wrote:

Is it possible to replace only specific characters/text within a cell? For
example I have several cells that need to have one word in italtics, but when
I use find and replace, all words in the cell are changed to italics.


--

Dave Peterson
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
Find & Replace: find part cell, replace whole cell katy Excel Worksheet Functions 3 April 3rd 23 01:20 PM
Can I replace a ' at the beginning of a text cell using Replace Hilde Excel Discussion (Misc queries) 4 September 10th 07 06:22 PM
Find and Replace without changing font Tony Logan Excel Discussion (Misc queries) 4 December 11th 06 03:02 PM
Excel - create button to replace cell content with cell value blackmot Excel Worksheet Functions 3 December 7th 05 05:10 PM
Find and replace of word causes change of font formatting jwa90010 New Users to Excel 4 July 22nd 05 08:10 PM


All times are GMT +1. The time now is 03:11 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"