excel求助怎样编写vba代码改变“指定”字符的颜色? 下载本文

内容发布更新时间 : 2024/5/20 18:26:49星期一 下面是文章的全部内容请认真阅读。

excel求助怎样编写vba代码改变“指定”字符的颜色?

老司机带带我最佳答案165 12#发表于 2016-6-14 21:40 |

只看该作者

兰色幻想Excel数据透视表全28集高清视频教程,淘宝热销售中

song_syl灰太狼 发表于 2016-6-14 21:37

这个代码有个小问题:

就是 当你在 “不同” 的单元格 中 输入 “卖品”、“赠品” 或者 输入 ” ...Private Sub Worksheet_Change(ByVal Target As Range)

Dim str$

If Target.Count > 1 Then Exit Sub

str = \卖品\ '要上色的字符串

If InStr(Target.Value, str) Then

Target.Characters(Start:=InStr(Target.Value, str),

Length:=Len(str)).Font.ColorIndex = 3 '这个3是设置颜色的

str = \赠品\ '要上色的字符串

If InStr(Target.Value, str) Then

Target.Characters(Start:=InStr(Target.Value, str),

Length:=Len(str)).Font.ColorIndex = 5 '这个5是设置颜色的

str = \退货\ '要上色的字符串

If InStr(Target.Value, str) Then

Target.Characters(Start:=InStr(Target.Value, str),

Length:=Len(str)).Font.ColorIndex = 8 '这个8是设置颜色的

str = \其他原因退回\ '要上色的字符串

If InStr(Target.Value, str) Then

Target.Characters(Start:=InStr(Target.Value, str),

Length:=Len(str)).Font.ColorIndex = 13 '这个13是设置颜色的

End Sub复制代码