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?)
 

Some videos you may like

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Yard

Well-known Member
Joined
Nov 5, 2008
Messages
1,929
Not particularly difficult in VBA, but IMHO it's off the end of the "effort applied vs. benefit achieved" scale!

Hold on, I'll try it while I have a brew......
 
Last edited:

preqin

Board Regular
Joined
Mar 15, 2005
Messages
83
It's not me that wants it to be bold, but it IS me who has to try and do it... put it that way ;)

How would I go about this then? - Can someone give me a fairly basic guide?
 

Yard

Well-known Member
Joined
Nov 5, 2008
Messages
1,929
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
 

preqin

Board Regular
Joined
Mar 15, 2005
Messages
83
Thanks Yard, I just gave that a try but I could not get it to work.

I right clicked sheet one and went to view code and pasted in your code.

I then typed some text in to A1 and A2

In A3 I tried my concatenate as specified in the first post with teh ", " as I see you have used this as part of your code, however, A3 was simply the concatenate of both cells, and didnt bold anything - regardless of whether the original cells were bolded or not...

What am I doing wrong!?
 

Yard

Well-known Member
Joined
Nov 5, 2008
Messages
1,929
You need to put the code in a normal Module, NOT the worksheet code.

From Excel, hit Alt+F11.
On the left, right-click the sheet you are working on and Insert>Module.
PAste the code into that new window.
Now run it.
 

preqin

Board Regular
Joined
Mar 15, 2005
Messages
83
Cool, I have that working now, thanks,

You're gonna go bonkers now, but I tinkered with it so I could change where it looks and where it places the results for a more realistic application than my example... however, how can I swap around the part which gets bolded to the first part?!

Code:
With Range("C1").Characters(Start:=Part1Len + DividerLen, Length:=Part2Len).Font
        .FontStyle = "Bold"
I gather it involves editing part of that statement, however, I am not sure which, and some trial and error has resulted in just error thus far!
 

Yard

Well-known Member
Joined
Nov 5, 2008
Messages
1,929
Should be simple to break down.

Part1Len is the first part of the concatentation. In the resulting value, it starts at character 1 and goes as far as there are characters in A1.

So, Part1Len = the length of the A1 string

So change your statement to

Code:
With Range("C1").Characters(Start:=1, Length:=Part1Len).Font
        .FontStyle = "Bold"
The Start:=1 tells it to begin from the 1st character, and the Length:=Part1Len tells it to apply the following instruction (i.e. Bold) to however many characters it found in cell A1.

Easy!
 

preqin

Board Regular
Joined
Mar 15, 2005
Messages
83
I kinda sussed that out, the issue was then (I think) how I stick the other bits to that part of the string:

Code:
With Range("C1").Characters(Start:=1, Length:=Part1Len).Font
        .FontStyle = "Bold"
Makes sense, so I thought sticking the other bits on should just be a case of adding them to the end of the string:

Code:
With Range("C1").Characters(Start:=1, Length:=Part1Len).Font
        .FontStyle = "Bold"+ DividerLen, Length:=Part2Len
Failed though... I think it's a brackets issue, but I did try putting brackets around the whole lot (i.e. from the 's' of characters and the n of 'len' a the end) and that failed too!

Quite annoying as I'm usually OK at seeing what something is doing and adapting it!!
 

Watch MrExcel Video

Forum statistics

Threads
1,102,134
Messages
5,484,935
Members
407,475
Latest member
Dix_Fix

This Week's Hot Topics

  • Finding issue in If elseif else with For each Loop
    Finding issue in If elseif else with For each Loop I have tried this below code but i'm getting in Y column filled with W005. Colud you please...
  • MsgBox Error
    Hi Guys, I have the below error show up when i try and run my macro in File1 but works fine if i copy and paste the same code into file2. [ATTACH...
  • CELL FORMAT - IF CONDITION
    My Cell Format is [B]""0.00" Cr". [/B]But in the cell, it is showing 123.00 for editing. (123 is entry figure). (Data imported from other...
  • Show numbers nearly the same
    Is this possible. I have a number that can change very time eg 0.00001234 Then I have a lot of numbers 0.0000001, 0.0000002, 0.00000004...
  • Please i need your help to create formula
    I need a formula in cell B8 to do this >>if b1=1 then multiply ( cell b8) by 10% ,if b1=2 multiply by 20%,if=3 multiply by 30%. Thank you in...
  • Got error while adding column and filter
    Got error while adding column and filter In column Z has some like "Success" and "Error". I want to add column in AA if the Z cell value is...
Top