Formatting a formula

A

Alex

This is probably not possible, but I figure there's not harm in asking.

I know that if I have a cell containing "apples and oranges" and I highlight
"apples" and click the bold button, only "apples" will be in bold face and
"oranges" will stay regular. Is it possible to do this with a formula. What I
mean is this:

A1="apples "
A2="and oranges"
A3=A1&A2

Is there any way that in A3 only "apples" be in bold face?

Alex
 
D

Dave Peterson

Formulas don't allow this kind of character by character formatting.

You could convert it to values and do the formatting, though.
 
F

FSt1

hi
this type of formating can only be done for text.
it can't be done for true numbers or formulas.
it can be done for numbers formated as text.

Regards
FSt1
 
R

Ron Rosenfeld

This is probably not possible, but I figure there's not harm in asking.

I know that if I have a cell containing "apples and oranges" and I highlight
"apples" and click the bold button, only "apples" will be in bold face and
"oranges" will stay regular. Is it possible to do this with a formula. What I
mean is this:

A1="apples "
A2="and oranges"
A3=A1&A2

Is there any way that in A3 only "apples" be in bold face?

Alex

To accomplish this, you could
Implement your formula in a VBA Macro
Have the VBA Macro output a text string to the cell
Format the text cell appropriately.

By using an event-triggered macro, you could almost emulate the functionality
of a formula.

Perhaps if you can be more specific as to your requirements ...
--ron
 
A

Alex

Thanks to everyone for replying.

I hope I can accurately describe what I am trying to do: I have three sets
of data in three columns. Some cells in these columns have data, some are
empty. I also have an output cell that, based on the value of a combo box,
joins together and outputs the data contained in these columns into a single
cell. My ideal condition is that whenever data from column 1 exists, then
that data (and only that data) must stand out in some way (bold face,
different color, whatever). What I'm doing right now is using conditional
formatting to change the font of the whole output cell based on whether data
from column 1 exists or not. My problem with doing it this way is that the
emphasis is not where I would like it to be. I hope I wasn't too confusing :)

Thanks again,
Alex
 
R

Ron Rosenfeld

Thanks to everyone for replying.

I hope I can accurately describe what I am trying to do: I have three sets
of data in three columns. Some cells in these columns have data, some are
empty. I also have an output cell that, based on the value of a combo box,
joins together and outputs the data contained in these columns into a single
cell. My ideal condition is that whenever data from column 1 exists, then
that data (and only that data) must stand out in some way (bold face,
different color, whatever). What I'm doing right now is using conditional
formatting to change the font of the whole output cell based on whether data
from column 1 exists or not. My problem with doing it this way is that the
emphasis is not where I would like it to be. I hope I wasn't too confusing :)

Thanks again,
Alex

I'm not sure how you get the information as to which row (or cells) to use in
each of the three columns, but the below macro should get you started.

It combines the contents of B1:D1 with " and " between each element.
It writes the result of the concatenation into A1
If there is anything in B1, that part of the string in A1 will be BOLD and RED.

You should be able to modify it to your requirements:

To enter this Macro (Sub), <alt-F11> opens the Visual Basic Editor.
Ensure your project is highlighted in the Project Explorer window.
Then, from the top menu, select Insert/Module and
paste the code below into the window that opens.

To use this Macro (Sub), <alt-F8> opens the macro dialog box. Select the macro
by name, and <RUN>.

=======================================
Option Explicit
Sub ConcatFormat()
Dim rSrc As Range, rDest As Range
Dim s As String, v() As String
Dim c As Range
Dim i As Long

'I don't know who you determine which three columns
' or cells to use. You'll have to do that.
'This is just for testing

Set rSrc = Range("B1:D1")
Set rDest = Range("A1")

i = -1
For Each c In rSrc
If c.Value <> "" Then
i = i + 1
ReDim Preserve v(0 To i)
v(i) = c.Value
End If
Next c
s = Join(v, " and ")

With rDest
.Clear
.NumberFormat = "@"
.Value = s
i = Len(rSrc(1, 1).Value)
'BOLD RED only contents of first cell/column
If i > 0 Then
With .Characters(1, i)
.Font.Bold = True
.Font.Color = vbRed
End With
End If
End With
End Sub
==========================================
--ron
 

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