我在单元格 A1 中有句子“我想要其中的 50 个,请”。我想让任何数字字符变成红色文本(只是数字字符)。我该怎么做呢?这是我所拥有的框架......
Sub RedText()
Dim i As Integer
For i = 1 To Len(Cells(1, 1).Value)
If IsNumeric(Mid(Cells(1, 1).Value, i, 1)) = True Then
'make the character red text
End If
Next
End Sub
任何帮助将不胜感激。
最佳答案
您可以使用 characters(start, length) 属性来执行此操作。您还可以将文本存储在字符串中并在其上循环,当您使用多个单元格时会更快。这是一个例子:
Sub RedText()
Dim i As Long
Dim text As String
text = Cells(1, 1).Value
For i = 1 To Len(text)
If IsNumeric(Mid$(text, i, 1)) = True Then
Cells(1, 1).Characters(i, 1).Font.Color = vbRed
End If
Next
End Sub
https://stackoverflow.com/questions/7618121/