Concatenate and bold

AroraMandeep

New Member
Joined
Apr 30, 2019
Messages
3
Hi,

i am ccocatenating 2 columns that are I and J, and i want the test in column I to be bold.
how can i do it?
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Can you give us a bit more information ?
You want the resultant cell to be part Bold and part normal ??
 
Upvote 0
Amend value of variables to match your requirements
Code:
Sub Concat()
    Const resultCol = "[COLOR=#ff0000]K[/COLOR]", fRow = [COLOR=#ff0000]2[/COLOR]
    
    Dim lRow As Long, r As Long, x As Long, ws As Worksheet, iStr As String, jStr As String, cel As Range
    Set ws = [COLOR=#ff0000]ActiveSheet[/COLOR]
    lRow = WorksheetFunction.Max(ws.Range("I" & Rows.Count).End(xlUp).Row, ws.Range("J" & Rows.Count).End(xlUp).Row)
    
    For r = fRow To lRow
        Set cel = ws.Cells(r, resultCol)
        iStr = ws.Cells(r, "I").Value
        jStr = ws.Cells(r, "J").Value
        cel.Value = iStr & jStr
        cel.ClearFormats
        For x = 1 To Len(iStr)
            cel.Characters(x, 1).Font.Bold = True
        Next x
    Next r
End Sub
 
Last edited:
Upvote 0
Yes
i want text from column I to be bold and column J to be normal

Welcome to the board Mandeep. You can try the following macro to achieve your purpose. Change the Startrow and Endrow values as per your requirement.

Sub Concat_BoldColi()


Startrow = 1
Endrow = 20
ValueColumn = 11
ColBold = 9
ColReg = 10
RowNum = Startrow
Do While RowNum < Endrow
RegValue = Cells(RowNum, ColReg).Value
RegValLength = Len(RegValue)
BoldValue = Cells(RowNum, ColBold).Value
BoldValLength = Len(BoldValue)
Cells(RowNum, ValueColumn) = BoldValue + " " + RegValue
Cells(RowNum, ValueColumn).Select
With ActiveCell.Characters(Start:=1, Length:=BoldValLength).Font
.FontStyle = "Bold"
End With
RowNum = RowNum + 1
Loop


End Sub
 
Upvote 0
hi,

Thank you for the solution, it worked but it is making text form both columns bold. I only wanted text of one column to be bold.
 
Upvote 0
Delete the existing values in column K and then try the macro again
 
Upvote 0
@AroraMandeep @Sanjeev1976

Delete the existing values in column K and then try the macro again
- that is not correct
- clear formats NOT values (refer to solution in post#4)

Code:
Sub Concat_BoldColi()

Startrow = 1
Endrow = 20
ValueColumn = 11
ColBold = 9
ColReg = 10
RowNum = Startrow
Do While RowNum < Endrow
    RegValue = Cells(RowNum, ColReg).Value
    RegValLength = Len(RegValue)
    BoldValue = Cells(RowNum, ColBold).Value
    BoldValLength = Len(BoldValue)
    Cells(RowNum, ValueColumn) = BoldValue + " " + RegValue
    Cells(RowNum, ValueColumn).Select
[COLOR=#ff0000]    ActiveCell.ClearFormats[/COLOR]
    With ActiveCell.Characters(Start:=1, Length:=BoldValLength).Font
        .FontStyle = "Bold"
    End With
    RowNum = RowNum + 1
Loop
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,250
Members
452,623
Latest member
Techenthusiast

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