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

It is no trouble, so don't worry about that. If it turns out you need me to
look into this further, just let me know.

--
Rick (MVP - Excel)


"Dallas" wrote in message
...
I was repeatedly running these macros on the same file which I placed every
situation I knew that I needed the macro to fix. The workbook I was using
must have gotten corrupted during one of the crashes I experienced trying
get
this macro to work. I copied your code over and tried it again and got the
same problem so I opened another file that had the same situation that was
giving me trouble and ran the macro and it ran perfectly. Hopfuly that is
all
that it was. I will continue test this on other other files and hopfully I
won't have anymore trouble. Thank you for all of your help.


"Rick Rothstein" wrote:

Okay, I tried out the code after switching the fonts and everything
worked
as it was supposed to... no doubled up letters, no misapplied font
changes... in other words, I cannot duplicate the problem you are
reporting.
Are you sure you are using the exact code I posted (with the mistakes
corrected) and not one of your modifications? Here is the code again,
with
the corrections I fixed earlier; replace what you are now using with it
and
tell me if you are still seeing the problem...

Sub SubstituteCharacters()
Dim X As Long
Dim R As Range
Dim Before As Variant
Dim After As Variant
For Each R In Worksheets("Sheet2").UsedRange
If R.Value Like "*[6fw]*" Then
For X = 1 To Len(R.Value)
With R.Characters(X, 1)
If .Font.Name = "UniversalMath1 BT" Then
If .Text = "6" Then
.Font.Name = "Calibri"
.Text = Chr(177)
.Font.FontStyle = "Regular"
.Font.Size = 12
End If
ElseIf .Font.Name = "GDT" Then
If .Text = "f" Then
.Font.Name = "Arial"
.Text = Chr(216)
.Font.FontStyle = "Regular"
.Font.Size = 10
ElseIf .Text = "w" Then
.Font.Name = "Neuropol"
.Text = "V"
.Font.FontStyle = "Regular"
.Font.Size = 11
End If
ElseIf .Font.Name = "Symbol" Then
If .Text = "f" Then
.Font.Name = "Arial"
.Text = Chr(216)
.Font.FontStyle = "Regular"
.Font.Size = 10
End If
End If
End With
Next
End If
Next
End Sub

--
Rick (MVP - Excel)


"Dallas" wrote in message
...
Here is the original text
wf.840
(GDT,GDT,Arial,Arial,Arial,Arial)
Part of the problem is that as I mentioned on my first post I no longer
have
these fonts either they were spacific to Autocad but when we got new
computers we didn't carry Autocad over to the new ones because our 3D
sofware
has a DWG editor that does everything we were using the older version
of
Autocad for. I have a font attached to the 3D modeling software but
only 3
of
the company's computers are loaded with this software and all of the
computers need to be able to view the correct text. I really appreciate
all
of your help. I won't get another chance to try anything until somtime
Monday. Thanks alot.

"Rick Rothstein" wrote:

I've looked over my code and I can't see why what you are describing
is
happening. I will try to test the code, but I need some more data from
you
first. I don't have all of the fonts installed that you are using, so
I
will
have to try and substitute ones I have for those I don't have. In
order
to
do this successfully, you need to tell me exactly what is in the cell
you
wrote about BEFORE any code is run against it (I can't tell if the V
in
Vf.840 was original or if that was a substituted character). So, show
me
the
exact text in the cell before anything changes it and, underneath
that,
show
me what each character's font name is (use a comma delimited list of
font
names, one font name per character, in the same order as the listed
characters). Once you have done that, I'll reconstruct the text in the
cell
using fonts I have and then see if I can duplicate the problem here;
and,
if
I can, hopefully modify the code to fix it.

--
Rick (MVP - Excel)


"Dallas" wrote in message
...
That helps with the error and Excel locking up but still on that
same
cell
with the two symbols side by side It changed the entire cells font
to
Neuropole and it displays two f's but the formula line only shows
one.
The
changed cell reads Vff.840 and the formula line reads Vf.840. Any
sugestions
on this?
Again Thank You.

"Rick Rothstein" wrote:

If R.Value Like "*6*" Then

Sorry, I forgot to modify the above line. Use the following line of
code
instead of that one (leave the rest of my code as I originally
posted
it)...

If R.Value Like "*[6fw]*" Then

--
Rick (MVP - Excel)


"Dallas" wrote in message
...
I tried somthing similar already but I went ahead and tried this
one.
The
first time I ran it it skipped over any cell that didnt' have a 6
in
it
so
ont the line that reads
If R.Value Like "*6*" Then
to
If R.Value Like "*" Then
When I ran the macro this time I had the same problem as before.
It
fixes
everything up to the cell that has the two symbols side by side
in
the
same
font and changes both w and f characters to Neuropole font and w
to
V.
Then
Excel Locks up and when I End Task in Windows Task Manager VBA
pops
up
the
error "Unable to get the Font property of the Characters class"
and
proceeds
to highlight the line:
If .Font.Name = "UniversalMath1 BT" Then
When you look at the code it should work but it doesn't. I'm
getting
pretty
frustrated and I need a solution to this problem. Thank you for
your
continued support.

"Rick Rothstein" wrote:

Give this macro a try (I didn't test it, but I'm pretty sure it
will
work)...

Sub SubstituteCharacters()
Dim X As Long
Dim R As Range
Dim Before As Variant
Dim After As Variant
For Each R In Worksheets("Sheet1").UsedRange
If R.Value Like "*6*" Then
For X = 1 To Len(R.Value)
With R.Characters(X, 1)
If .Font.Name = "UniversalMath1 BT" Then
If .Text = "6" Then
.Font.Name = "Calibri"
.Text = Chr(177)
.Font.FontStyle = "Regular"
.Font.Size = 12
End If
ElseIf .Font.Name = "GDT" Then
If .Text = "f" Then
.Font.Name = "Arial"
.Text = Chr(216)
.Font.FontStyle = "Regular"
.Font.Size = 10
ElseIf .Text = "w" Then
.Font.Name = "Neuropol"
.Text = "V"
.Font.FontStyle = "Regular"
.Font.Size = 11
End If
ElseIf .Font.Name = "Symbol" Then
If .Text = "f" Then
.Font.Name = "Arial"
.Text = Chr(216)
.Font.FontStyle = "Regular"
.Font.Size = 10
End If
End If
End With
Next
End If
Next
End Sub

--
Rick (MVP - Excel)


"Dallas" wrote in message
...
Sorry for the confusion. Here is what I need changed.

"UniversalMath1 BT" "6" to "Calibri" "Chr(177)" "12"

"GDT" "f" to "Arial" "Chr(216)" "10"

"Symbol" "f" to "Arial" "Chr(216)" "10"

"GDT" "w" to "Neuropol" "Chr(86)" "11"

Thanks again for your help.

"Rick Rothstein" wrote:

Can you clarify the FROM and TO font names and symbols...
your
text
description and your code appear to be different. List them
across
in
this
order for us (one conversion per line) please...

"From Font Name" "From Character" "To Font Name" "To
Character"
"To
Size"

--
Rick (MVP - Excel)


"Dallas" wrote in message
...
Some more Help Please! I guess I should have mentioned
before
that I
have
other symbols I neet to fix as well. The problem seems to
be
when
I
have
two
symbols next to each other in the same font. When I run a
variation
of
your
macro It changes the font on both of them and then excel
locks
up.
The
error
that I get is
"Unable to get the Font property of the Character class".
The
cell
that
the
error occurs on reads wf.840 where the w represents a
countersink
symbol
in
font "GDT"
and "f" represents a diameter symbol in the same font. The
rest
of
the
characters in the cell are in the "Arial" font. I need to
Change
the
"w"
to a
capital "V" in the "Neuropol" and the "f" to the diameter
symbol
or
Chr(216)
in th "Arial". I als need the macro to look for "f" in the
"Symbol"
font
and
change it to the the diameter symbol. When I use Dave's
macro
it
runs
without
errors but if I search for the "f" first on the same cell
it
changes
the
font
on both the "f" and the "w" to "Arial" and if I search for
the
"w"
first
it
changes the font of the whole cell to "Neuropol". I would
like


 
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 09:26 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"