更改单元格中某些字符的颜色 [英] Change color of certain characters in a cell

查看:119
本文介绍了更改单元格中某些字符的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在单元格A1中有句话我想要其中的50个。我想使任何数字字符红色文本(只是数字字符)。我该怎么做?这是我所拥有的框架...

I have the sentence "I would like 50 of those, please" in cell A1. I want to make any numeric characters red text (just the numeric characters). How do I do this? Here's the frame of what I have...

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

任何帮助将不胜感激。

推荐答案

您可以使用 开始,长度 属性来执行此操作。您还可以将文本存储在字符串中并循环使用,当使用多个单元格时,文本将更快。这是一个例子:

You can use the characters(start, length) property to do this. You can also store the text in a string and loop on that, which will be faster when you work with many cells. Here is an example:

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

这篇关于更改单元格中某些字符的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆