Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default cell format changing when when using search and replace.

This sounds like it's going to be a difficult problem to solve. It sounds
like you will need to save each character's font attributes of each cell
being changed and then reset the text after it is replaced in the cell. Hope
your deadline is not too soon. Here are some examples of setting and finding
individual character's attributes in a cell:

Dim i As Long

Cells(1, 1).ClearFormats
Cells(1, 1) = "Hello World"
Cells(1, 1).Characters(1, 5).Font.Bold = True

For i = 1 To Cells(1, 1).Characters.Count
If Cells(1, 1).Characters(i, 1).Font.Bold Then
MsgBox Cells(1, 1).Characters(i, 1).Text & " is BOLD"
End If
Next i


" wrote:

I have a large number of macros that change the formating of cells (fonts, etc).
I'm having trouble replacing text on cells that contain multiple fonts in the same cell. Replacing any any text will changethe formating in the cell. Can anyone help me because on a deadline and cant figure this out.

The problem can be recreated easily by putting a line of text into a cell and making part of the cell BOLD. Now do a search and replace on any part of the cell. The BOLD text will no longer be bold.




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default cell format changing when when using search and replace.

Try something like this (run it in the Workbook_Open procedure)

Dim i As Long
Dim OneChr() As String
Dim IsBold() As Boolean
Dim FntName() As String

Cells(1, 1).ClearFormats
Cells(1, 1) = "Hello World"
Cells(1, 1).Characters(1, 5).Font.Bold = True
Cells(1, 1).Characters(1, 5).Font.Name = "Courier New"
MsgBox "Continue"

ReDim OneChr(Cells(1, 1).Characters.Count)
ReDim IsBold(Cells(1, 1).Characters.Count)
ReDim FntName(Cells(1, 1).Characters.Count)

For i = 1 To Cells(1, 1).Characters.Count
OneChr(i) = Cells(1, 1).Characters(i, 1).Text
IsBold(i) = Cells(1, 1).Characters(i, 1).Font.Bold
FntName(i) = Cells(1, 1).Characters(i, 1).Font.Name
Next i

Cells(1, 1).ClearFormats
MsgBox "Continue"

For i = 1 To UBound(OneChr)
Cells(1, 1).Characters(i, 1).Text = OneChr(i)
Cells(1, 1).Characters(i, 1).Font.Bold = IsBold(i)
Cells(1, 1).Characters(i, 1).Font.Name = FntName(i)
Next i


"Charlie" wrote:

This sounds like it's going to be a difficult problem to solve. It sounds
like you will need to save each character's font attributes of each cell
being changed and then reset the text after it is replaced in the cell. Hope
your deadline is not too soon. Here are some examples of setting and finding
individual character's attributes in a cell:

Dim i As Long

Cells(1, 1).ClearFormats
Cells(1, 1) = "Hello World"
Cells(1, 1).Characters(1, 5).Font.Bold = True

For i = 1 To Cells(1, 1).Characters.Count
If Cells(1, 1).Characters(i, 1).Font.Bold Then
MsgBox Cells(1, 1).Characters(i, 1).Text & " is BOLD"
End If
Next i


" wrote:

I have a large number of macros that change the formating of cells (fonts, etc).
I'm having trouble replacing text on cells that contain multiple fonts in the same cell. Replacing any any text will changethe formating in the cell. Can anyone help me because on a deadline and cant figure this out.

The problem can be recreated easily by putting a line of text into a cell and making part of the cell BOLD. Now do a search and replace on any part of the cell. The BOLD text will no longer be bold.




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
cell format changing when when using search and replace. Excel Discussion (Misc queries) 0 January 6th 06 02:41 AM
cell format changing when when using search and replace. Excel Discussion (Misc queries) 0 January 6th 06 02:41 AM
cell format changing when when using search and replace. No Name Excel Programming 0 December 13th 05 03:33 AM
cell format changing when when using search and replace. No Name Excel Programming 0 December 13th 05 03:33 AM
how do i replace ( with / without changing format to fraction Splt Window Diner Excel Worksheet Functions 2 August 19th 05 10:00 PM


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