Configure VBA to run macro for all cells in column

bigalpha

Registered User.
Local time
Today, 07:00
Joined
Jun 22, 2012
Messages
415
I have this snippet of code I found and it works perfectly. It concatenates cells and applies a bold formatting to only one part of the concatenation.

Except it only works with the referenced cells (A1, B1). I am looking to have this work for each row automatically (A2, B2; A3, B3, etc).

Code:
Sub BoldPartText()
Dim Part1Len, Part2Len, DividerLen As Integer
Dim Divider As String
Part1Len = Len(Range("A1"))
Part2Len = Len(Range("b1"))
Divider = Chr$(10)
DividerLen = Len(Divider)
Range("e1").Clear

Range("e1") = Range("A1") & Divider & Range("b1")
With Range("e1").Characters(Start:=1, Length:=Part1Len).Font
        .FontStyle = "Bold"
End With
End Sub
 
Try this, I have corrected the Dim statement also

Brian

Code:
Sub BoldPartText()
Dim Part1Len As Integer, Part2Len As Integer, DividerLen As Integer
Dim Divider As String
Dim n As Long, rowcount As Long

rowcount = Range("A1").CurrentRegion.Rows.Count
For n = 1 To rowcount
    Part1Len = Len(Cells(n, 1))
    Part2Len = Len(Cells(n, 2))
    Divider = Chr$(10)
    DividerLen = Len(Divider)
    Cells(n, 5).Clear

    Cells(n, 5) = Cells(n, 1) & Divider & Cells(n, 2)
    With Cells(n, 5).Characters(Start:=1, Length:=Part1Len).Font
        .FontStyle = "Bold"
    End With
Next n
End Sub
 
Works perfectly, thanks! Your solution isn't close to any solutions I tried.
 
Happy to help , and glad the old brain hasn't completely gone , but old habits die hard and I forgot that you can code

Cells(n,"e")

For example , which makes things easier, ie the column index can be quoted in alpha if not dynamic.

Brian
 
Happy to help , and glad the old brain hasn't completely gone , but old habits die hard and I forgot that you can code

Cells(n,"e")

For example , which makes things easier, ie the column index can be quoted in alpha if not dynamic.

Brian

So this references column E?
 
Yes, instead of the index number you can use the column letters

Cells(n , "A") for col A etc

Brian
 
Awesome, that's handy to know. Thanks again for your time, you've been a huge help!
 

Users who are viewing this thread

Back
Top Bottom