View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default Merging cells and formats

Walter,
You can use the Worksheet_Change event to update the target cell. My
1st inclination is to put color~size~bold for the source cells into an
array, then process them as shown by Claus to apply each source cell's
formatting to each character in the target cell, respectively.

You may even include the length of each source cell so formatting the
target matches correctly when source cells contain more than 1
character. This, of course, will dictate how you construct your loop.
I'd start with working with a counter so the loop acts on each element
of the source array, and the counter increments to match the starting
character in the target cell...

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Target.Column = Columns("D").Column Then Exit Sub

'Required to obviate recursion.
Application.EnableEvents = False

Dim vSrc, n&, lChr&, rngSrc As Range
Const lOffset& = -3: Const lResize& = 3
Set rngSrc = Target.Offset(0, lOffset).Resize(1, lResize)
vSrc = rngSrc: lChr = 1

'Required to format characters
Target.Value = Target.Value

For n = LBound(vSrc, 2) To UBound(vSrc, 2)
With Target.Characters(lChr, Len(vSrc(1, n)))
.Font.Size = rngSrc.Cells(n).Font.Size
.Font.Bold = rngSrc.Cells(n).Font.Bold
.Font.Color = rngSrc.Cells(n).Font.Color
End With
'Increment to next start position
lChr = lChr + Len(vSrc(1, n))
Next 'n
Application.EnableEvents = True
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion



---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com