LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Search and Replace a Spacific Character with Conditional Formating


I need a macro that will look through each character in each cell of a
worksheet and look for a spacific character with a spacific font and change
it to a different charater and a new font and size. I was using a couple of
symbol fonts that were attached to software that we did not carry over when
we upgraded to new computers. I borrowed a macro form another post and
modified it to meet what I needed but it only finds the first character match
of each cell then moves to the next cell. For example I need 16-3/461/8 to
read 16-3/4±1/8 where the first "6" in the original text has a font callout
of "Arial" and the second "6" has a font callout of "UniversalMath1 BT". Here
is a sample of the macro I am using. Please Help!

Option Explicit
Sub FixSymbols()

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
Dim myValue As Variant
Dim Counter As Variant
Dim myNum As Variant

myValue = ActiveWorkbook.Sheets.Count
Dim ChkLastUntil()
Counter = 0
myNum = myValue
Do Until myNum = 0
myNum = myNum - 1
Counter = Counter + 1

Set wks = Worksheets(myValue - Counter + 1)

'change this to the list of words to find
myWords = Array("6")

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

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
If FoundCell.Characters _
(Start:=StartPos, _

Length:=Len(myWords(wCtr))).Font _
.Name = "UniversalMath1 BT"
Then
With FoundCell.Characters _
(Start:=StartPos, _

Length:=Len(myWords(wCtr))).Font
.Name = "Calibri"
.FontStyle = "Regular"
.Size = 12
End With

With FoundCell.Characters _
(Start:=StartPos, _
Length:=Len(myWords(wCtr)))
.Text = "±"
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

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

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

Loop
MsgBox "FixSymbols Done! "

End Sub

 
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
Character search and replace jkollenbroich Excel Worksheet Functions 1 February 3rd 09 08:14 PM
Date Formating and building character strings C Brandt Excel Discussion (Misc queries) 5 August 18th 07 03:39 AM
Install dates formating using conditional formating? Jerry Eggleston Excel Discussion (Misc queries) 2 November 9th 05 05:49 PM
Search and replace character with in excell cell JRR Excel Discussion (Misc queries) 1 July 22nd 05 08:30 PM
How to replace this character ... Harish Mohanbabu Excel Programming 2 February 18th 04 04:20 PM


All times are GMT +1. The time now is 05:30 PM.

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"