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: 4
Default Appending to a Cell doesn't keep format of existing content

I am writing some macros that appeds to a cell (using CHR(10) for line
breaks). I can't figure out a way to format each line differently
(i.e. bold, normal, italic, red, blue, etc.):

For example, I want to write following in cell A1 dynamically using
VBA:

=====================================

John Doe (BOLD)
James Smith (NORMAL)
Rob Smith (BOLD)

After the macro runs, all 3 lines above are NORMAL. After the 1st line
was written, it was bold, but then it lost it's formatting after the
2nd and 3rd lines were appended.

Here is my code to format data:

Private Sub formatData (valueToAppend as String, gender as String)
Dim iStart As Integer
Dim iLen As Integer

' apply format only to the data being appended. Don't touch
existing data
iLen = Len(valueToAppend)
iStart = Len(Range("A1").Value)
If (iStart = iLen) Then
iStart = (iStart - iLen) + 1
Else
Exit Sub
End If

' Make females bold
If (gender = "F") Then
Range("A1").Characters(iStart, iLen).Font.Bold = True
End If

' reset the font to Normal for the following text
Range("A1").Characters(iStart + iLen, iStart + iLen + 1).Font.Bold
= False

End Sub

=====================================

I'd appreciate any help greatly.

 
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
Changing the cell format doesn't change existing cell content Kate Excel Discussion (Misc queries) 2 January 14th 10 04:44 PM
Delete content of cell without erasing existing formula? duethckey Excel Discussion (Misc queries) 1 October 22nd 07 06:58 PM
Appending to existing function D.Jessup Excel Worksheet Functions 4 November 26th 06 10:43 AM
appending text to existing values anny Excel Worksheet Functions 3 January 28th 06 06:24 PM
Is cell content text or numeric-need help with existing code dan Excel Programming 3 February 28th 04 07:18 PM


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