|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
我想将表格中的粗体字用[]括起来,先要判断,代码如下:
Sub 测试1()
Dim rg As Range
For Each rg In ActiveSheet.Range("A3:F52").Cells
For i = 1 To rg.Characters.Count
If rg.Characters(i).Font.Bold = True Then
If i = 1 Then
rg = "[" & Left(rg.Value, 1) & "]" & Right(rg.Value, Len(rg.Value) - 1)
Else
rg = Left(rg.Value, i - 1) & "[" & Mid(rg.Value, i, 1) & "]" & Right(rg.Value, Len(rg) - i)
End If
End If
Next
Set rg = Nothing
Next
End Sub
Sub 测试2()
For j = 1 To 4 Step 3
For i = 3 To 52
With Cells(i, j)
For x = 1 To .Characters.Count
If .Characters(x).Font.Bold = True Then
If x = 1 Then
.Value = "[" & Left(.Text, 1) & "]" & Right(.Text, Len(.Text) - 1)
Else
.Value = Left(.Text, x - 1) & "[" & Mid(.Text, x, 1) & "]" & Right(.Text, Len(.Text) - x)
End If
End If
Next
End With
Next
Next
End Sub
代码居然只能完成部分任务,而对于单元格中第一个位置的粗体,不闻不问,甚是奇怪,不知何故。
附件如下。
|
|