如何连接两列中的数据,但只在新列中以粗体显示部分数据?

我已经得到尽可能远的VBA代码,但我需要循环它,以便继续每一行,直到列A中没有值:

Sub BoldText() Dim Part1Len, Part2Len, DividerLen As Integer Dim Divider As String Part1Len = Len(Range("B4")) Part2Len = Len(Range("C4")) Divider = " :" DividerLen = Len(Divider) Range("E4") = Range("B4") & Range("C4") With Range("E4").Characters(Start:=1, Length:=Part1Len).Font .FontStyle = "Bold" End With End Sub 

您可以使用For Each循环遍历您希望评估的范围。

然后你可以使用行索引,为你循环的每一行。

 Sub BoldText() Dim Part1Len, Part2Len, DividerLen As Integer Dim Divider As String Dim c As Range, cRow As Long For Each c In Range("E4:E" & lrow(1)) cRow = c.Row Part1Len = Len(Range("B" & cRow)) Part2Len = Len(Range("C" & cRow)) Divider = " :" DividerLen = Len(Divider) c.Value = Range("B" & cRow) & Range("C" & cRow) With c.Characters(Start:=1, Length:=Part1Len).Font .FontStyle = "Bold" End With Next c End Sub 

编辑:

我意识到你想要的范围是dynamic的,我更新了上面的代码,你只需要包含这个function:

 Function lrow(ByVal colNum As Long) As Long lrow = Cells(Rows.Count, colNum).End(xlUp).Row End Function 

代码现在将循环,直到findColumn A的最后一行。