用粗体和斜体连接不同的单元格excel vba

时间:2013-07-12 12:16:37

标签: excel vba

Sub joint()
ActiveSheet.Range("a2", ActiveSheet.Range("a2").End(xlDown)).Select
Row = 2
col = 2
For Each Cell In Selection
country = Cells(Row, col)
Name = Cells(Row, col + 1)
honor = Cells(Row, col + 2)

Cells(Row, col + 8) = Name & ", " & country & ", " & honor

Row = Row + 1
Next
End Sub

我希望以连续的形式加粗名称和斜体。

例如

myname ,pak, ABC

1 个答案:

答案 0 :(得分:4)

在你的行之后:

Cells(Row, col + 8) = Name & ", " & country & ", " & honor

添加以下代码部分:

With Cells(Row, Col + 8)
    .ClearFormats
    .Characters(1, Len(Name)).Font.Bold = True
    .Characters(Len(Name) + 4 + Len(Country), Len(.Value)).Font.Italic = True
End With

并保持原样。

结果的屏幕截图: enter image description here