different text colours in the same cell in excel

G

Guest

I have a formula which copies the text in cell A2 into B2. The text is typed
in A2 in two different colours but when it is copied into B2 it shows in one
colour. Is it possible for it to show it in the same colours or is it
possible for me to have a function that locates a character and changes the
colour of that character only and not the remaining characters in the cell
 
D

Don Guillett

As long as it's NOT a formula you can do anything you like. Or, convert the
formula to a value and then do it.
To do with a macro, look in the vba help index for CHARACTER or record doing
it to see what happened.
 
G

Guest

Thanks Don, but i want it as a formula because i may keep changing the value
of the original cell... i didnt understand what you meant by the macro
feature...
thanks
Nipun
 
J

JE McGimpsey

one way:

Since you can't have multiple font colors in a cell containing a
formula, replace the formula with an event macro:

Put this Event macro in your worksheet code module (right-click the
worksheet tab and choose view Code):

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim i As Long
With Range("A2:B2")
If Not Intersect(Target, .Cells(1)) Is Nothing Then
On Error Resume Next
Application.EnableEvents = False
.Cells(2).Value = .Cells(1).Value
Application.EnableEvents = True
On Error GoTo 0
For i = 1 To Len(.Cells(1).Text)
.Cells(2).Characters(i, 1).Font.ColorIndex = _
.Cells(1).Characters(i, 1).Font.ColorIndex
Next i
End If
End With
End Sub
 
G

Guest

Thank You for replying... I understood your logic... I think it should
work... Im new to macros so please can you help me with executing it in
detail...
 
D

Don Guillett

this line changes your formula to a value which you said that you did NOT
want. Again, you can NOT do what you want. "People in hell want ice water"

.Cells(2).Value = .Cells(1).Value
 
G

Guest

Thanks for your response. I managed to get what i want by using your
suggestion of recording a macro.

Thank you very much for your time and energy.

cheers

Nipun
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top