LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Individual Character fonts in a cell

The real bad news is that if you don't keep track of the formatting (font, font
color, super/sub script, strikethrough, ...) on a character by character basis,
you'll end up with the formatting attribute for the first character (not the
default, IIRC).

Rick Rothstein wrote:

Your posting raised made me realize my code needed to be modified. Why? I
didn't take into account that other characters may be colored with colors
other than white or the default (usually black)... my prior code makes every
character the default color (usually black). Here is modified code which
preserves the existing non-white character colors while deleting the white
characters...

Sub DeleteWhiteCharacters()
Dim X As Long
Dim Z As Long
Dim LastRow As Long
Dim Chars As String
Dim Colors() As String
On Error GoTo Whoops
Application.ScreenUpdating = False
With Worksheets("Sheet1")
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For X = 1 To LastRow
Chars = .Cells(X, "A").Text
ReDim Colors(1 To Len(Chars))
For Z = 1 To Len(Chars)
If .Cells(X, "A").Characters(Z, 1).Font.ColorIndex = 2 Then
Mid(Chars, Z, 1) = Chr(1)
Colors(Z) = "XX"
Else
If .Cells(X, "A").Characters(Z, 1).Font.ColorIndex < 0 Then
Colors(Z) = "00"
Else
Colors(Z) = Format(.Cells(X, "A").Characters(Z,
1).Font.ColorIndex, "00")
End If
End If
Next
.Cells(X, "A").ClearContents
.Cells(X, "A").Value = Replace(Chars, Chr(1), "")
Colors =
Split(Application.WorksheetFunction.Trim(Replace(J oin(Colors), "XX", "")))
For Z = 1 To UBound(Colors)
If Colors(Z - 1) < "00" Then
.Cells(X, "A").Characters(Z, 1).Font.ColorIndex = CLng(Colors(Z -
1))
End If
Next
Next
End With
Whoops:
Application.ScreenUpdating = True
End Sub

--
Rick (MVP - Excel)

"Dave Peterson" wrote in message
...
It didn't work for me in xl2003.

But I figured I did something wrong.

It always came back that it couldn't find any matches to change.

I used asdfqwerasdf in a bunch of cells with qwer in white and both a&f's
automatic and s&d's in red.



Ron Rosenfeld wrote:

On Sat, 3 Jan 2009 15:09:38 +0100, "Petr Danes"
wrote:

Excel also has the FindFormat method in VBA and the format option in the
GUI
Find/Replace dialog. Either will probably be a good deal faster then
manually looping through each cell in 30,000 rows.

Pete

And what happened when you tested your suggestions against a cell in
which just
a few letters were differentially formatted, as the OP requested?
--ron


--

Dave Peterson


--

Dave Peterson


 
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 2007 - Formatting text in cell (character by character) TomC Excel Discussion (Misc queries) 0 January 29th 10 07:25 PM
Calculate and display individual error bars for individual points del Charts and Charting in Excel 2 March 31st 06 05:11 PM
Calculate and display individual error bars for individual points del Charts and Charting in Excel 1 March 31st 06 04:24 AM
How can I lengthen the drop down Fonts list to show more fonts at Moser D Excel Discussion (Misc queries) 1 February 5th 06 03:24 PM
2 different fonts in a cell Morrigan Excel Discussion (Misc queries) 6 November 10th 05 10:12 PM


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