vba - 更改单元格中某些字符的颜色

我在单元格 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/

相关文章:

python - 均匀地并排打印 2 个均匀填充的列表

c# - 如何在 c# 中将 Decimal 格式化为程序控制的小数位数?

c# - .NET 有免费的 SQL 格式化库吗?

regex - Powershell Parsing Help - 如何将文件夹名称列表输出到文本文

javascript - moment.js - 更改已格式化的过去日期的格式

python - 格式正确的乘法表

delphi - 如何格式化 DBGrid 列以显示两个小数位?

java - 如何用空格左填充整数?

go - 格式错误。新

.net - 格式化 json 文档