Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: Concatenate and bold - Excel 2007
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Mar 2005
    Posts
    83
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Concatenate and bold - Excel 2007

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

  2. #2
    Board Regular Yard's Avatar
    Join Date
    Nov 2008
    Location
    is always easier with the light on
    Posts
    1,869
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Concatenate and bold - Excel 2007

    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 by Yard; Nov 10th, 2008 at 07:40 AM.

  3. #3
    Board Regular
    Join Date
    Mar 2005
    Posts
    83
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Concatenate and bold - Excel 2007

    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?

  4. #4
    MrExcel MVP
    Join Date
    Apr 2006
    Posts
    19,708
    Post Thanks / Like
    Mentioned
    15 Post(s)
    Tagged
    2 Thread(s)

    Default Re: Concatenate and bold - Excel 2007

    Hi preqin

    I answered a similar question here:

    http://www.mrexcel.com/forum/showthr...88#post1731888

    HTH
    Kind regards
    PGC

    To understand recursion, you must understand recursion.

  5. #5
    Board Regular Yard's Avatar
    Join Date
    Nov 2008
    Location
    is always easier with the light on
    Posts
    1,869
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Concatenate and bold - Excel 2007

    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

  6. #6
    Board Regular
    Join Date
    Mar 2005
    Posts
    83
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Concatenate and bold - Excel 2007

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

  7. #7
    Board Regular Yard's Avatar
    Join Date
    Nov 2008
    Location
    is always easier with the light on
    Posts
    1,869
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Concatenate and bold - Excel 2007

    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.

  8. #8
    Board Regular
    Join Date
    Mar 2005
    Posts
    83
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Concatenate and bold - Excel 2007

    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!

  9. #9
    Board Regular Yard's Avatar
    Join Date
    Nov 2008
    Location
    is always easier with the light on
    Posts
    1,869
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Concatenate and bold - Excel 2007

    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!

  10. #10
    Board Regular
    Join Date
    Mar 2005
    Posts
    83
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Concatenate and bold - Excel 2007

    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!!

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •