Concatenate and bold - Excel 2007

preqin

Board Regular
Joined
Mar 15, 2005
Messages
83
I have a simple concatenate in Excel...

=CONCATENATE(A1, ", ", A2)

Which produces:

This is, my text

Now, I want 'my text' i.e. the contents of A2 to be in bold.

I've played with the TEXT() function before, as per this page:
http://www.techonthenet.com/excel/formulas/text.php

To get Excel to play nicely with date formats and stuff, however, my research has come to a dead end with Bold/Italic - with everyone suggesting that VBA is the only solution.

As I don't feel overly comfortable using VBA is there any other solution? (If not, is this a VBA 101 task or an advanced task?)
 
Not a brackets issue, more like a language issue. The With statement tells the code what to apply an instruction to. The following line tells it what that instruction is.

The + sign is a mathematical operator, so makes no sense in an expression like that!

I like your style though; trial and error is my best friend too...:)
 
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Ok, I've made some progress:

Code:
Sub BoldPartText()
Dim Part1Len, Part2Len, DividerLen As Integer
Dim Divider As String
Part1Len = Len(Range("A1")) + 1
Part2Len = Len(Range("B1"))
Divider = ", "
DividerLen = Len(Divider)

Range("C1") = Range("A1") & Divider & Range("B1")
With Range("C1").Characters(Start:=1, Length:=Part1Len).Font
        .FontStyle = "Bold"
End With
End Sub

I previously thought the with part was where the concatenating was occuring, I now see that
Code:
Range("C1") = Range("A1") & Divider & Range("B1")
is actually what produces the string, and the WITH part determines what part of the string to format, and how to format it.

One odd quirk - it seems that if I run it and then run it again it makes the whole string bold!! - even if I delete said string it still makes the whole lot in C1 bold! - If I edit C1 to be D1 and run it, it's fine in D1, run it again and it bolds all of D1.
 
Upvote 0
Thanks Yard - that worked a treat.

I definitly think I've actually learnt something about VBA today rather than simply copy/paste be a robot - which is good :)
 
Upvote 0
I liked the code. Simple and to the point. I have a similar situation but I need to apply it to the whole sheet. I need to concatenate column B with column G in column J. I have posted similar questions on this site but yours has been the most helpful so far. Look at my previous posts and you will see what I mean. I would appreciate any help you can give on this effort. Thank you.

Sub BoldPartText()
Dim Part1Len, Part2Len, DividerLen As Integer
Dim Divider As String
Part1Len = Len(Range("b2")) + 1
Part2Len = Len(Range("g2"))
Divider = " - "
DividerLen = Len(Divider)
Range("j2").Clear
Range("j2") = Range("b2") & Divider & Range("g2")
With Range("j2").Characters(Start:=1, Length:=Part1Len).Font
.FontStyle = "Bold"
End With
End Sub
 
Upvote 0
Hi..
Is it possible to make this vba code as function?
I know that with macro in vba bold sm text is pble.

Thanks in adv.
 
Upvote 0
Hi

If you mean a udf, a vba function that you would call from a formula in a cell, the answer is no. All the characters in the result of a formula will have the same format.
 
Upvote 0
Here’s my scenario: I’m trying to draw from multiple cells to have one cell that produces a sentence that looks like this:
“Great job with your homework. You have scored 100%. Your next assignment is lesson 2.”

I’m struggling to bold the “lesson 2”. Here’s an example of the formula I’m using in cell A3: =CONCATENATE("Great job with your homework. You have scored "&text(A1,”0%”),". Your next assignment is "&(A2))

I’ve tried to manipulate your code listed below with little success:
Sub BoldPartText()
Dim Part1Len, Part2Len, DividerLen As Integer
Dim Divider As String
Part1Len = Len(Range("A1")) + 1
Part2Len = Len(Range("A2"))
Divider = ". "
DividerLen = Len(Divider)

Range("A3") = Range("A1") & Divider & Range("A2")
With Range("A3").Characters(Start:=Part1Len + DividerLen, Length:=Part2Len).Font
.FontStyle = "Bold"
End With
End Sub

Any suggestions on how to make this happen?
 
Last edited:
Upvote 0
Hi,

How do I manipulate this for Excel 2010?

I get the following error message:
The name that you entered is not valid.
Reasons for this can include:
- The name does not begin with a letter or an underscore
- the name contains a space or other invalid characters
- the name conflicts with an Excel buil-in name or the name of another object in the workbook.

Code:
Sub BoldPartText()
Dim Part1Len, Part2Len, DividerLen As Integer
Dim Divider As String
Part1Len = Len(Range("A1")) + 1
Part2Len = Len(Range("A2"))
Divider = ", "
DividerLen = Len(Divider)

Range("A3") = Range("A1") & Divider & Range("A2")
With Range("A3").Characters(Start:=Part1Len + DividerLen, Length:=Part2Len).Font
        .FontStyle = "Bold"
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,026
Messages
6,122,738
Members
449,094
Latest member
dsharae57

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top