EXCEL中如何批量加粗单元格中部分文字内容 ?且单元格中有转行。

例如:要加粗部分已加粗。

用下面的代码去执行,在该表的代码窗口粘贴下面代码:
Sub aa()
Dim c, n
For Each c In ActiveSheet.Range("a1:a100") '假设数据范围为a1:a100,根据需要修改
If c <> "" Then
n = Len(c.Value)
If n <= 4 Then
c.Characters(Start:=1, Length:=n).Font.FontStyle = "加粗"
Else:
c.Characters(Start:=n - 4 + 1, Length:=4).Font.FontStyle = "加粗"
End If
End If
Next c
End Sub
右击表名 》查看代码,可以进入该表代码窗口,粘贴后,点击代码窗口上面的小绿色三角按钮

Sub aa()
Dim c, n
For Each c In ActiveSheet.Range("a1:a100") '假设数据范围为a1:a100,根据需要修改
If c <> "" Then
n = Len(c.Value)
If n <= 5 Then
c.Characters(Start:=1, Length:=n).Font.FontStyle = "加粗"
Else:
c.Characters(Start:=n - 5 + 1, Length:=5).Font.FontStyle = "加粗"
End If
End If
Next c
End Sub追问

这个不行,因加粗的内容是相同的,但位置不一样。谢谢

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-11-30
要加粗的部分有规律吗追问

加粗的是相同的文字,但单元格中有转段,内容也不相同。谢谢!

追答Sub s()
    n = Cells(Rows.Count, 2).End(3).Row
    For I = 1 To n
        T = Cells(I, 2)
        k = 1
        p = InStr(k, T, ":", vbTextCompare)
        Do While (p <> 0) And (k <> 0)
            Cells(I, 2).Characters(k, p - k).Font.FontStyle = "加粗"
            k = InStr(p, T, Chr(10), vbTextCompare)
            If k Then p = InStr(k, T, ":", vbTextCompare)
        Loop
    Next
End Sub

本回答被提问者和网友采纳
相似回答