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
1 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
1")
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