Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 3391|回复: 2

[已解决]负数红色在VBA中的表达

[复制链接]
发表于 2016-8-1 17:47 | 显示全部楼层 |阅读模式
诸位大侠:

我在编辑VBA语句时,要把对负数的颜色设置为红色:
    Range("F22").Select
    Selection.NumberFormatLocal = "#,##0_ ;[Red]-#,##0 "
可是因为Office中英文版的关系, 当别人使用该宏时, 会出错, Red应该改用汉字才能通过.

请问大家,如何修改以上语句,使得中英文都能运行通过. 谢谢
最佳答案
2016-8-1 18:04
直接判断数字,然后通过颜色参数值来做,参考代码
  1. Range("F22").Select
  2.     With Selection
  3.         If .Value < 0 Then
  4.             .Font.ColorIndex = 3
  5.         End If
  6.     End With
复制代码
发表于 2016-8-1 18:04 | 显示全部楼层    本楼为最佳答案   
直接判断数字,然后通过颜色参数值来做,参考代码
  1. Range("F22").Select
  2.     With Selection
  3.         If .Value < 0 Then
  4.             .Font.ColorIndex = 3
  5.         End If
  6.     End With
复制代码
回复

使用道具 举报

发表于 2016-8-1 18:16 | 显示全部楼层
删除语句中“[red]”,
后面加上一句:
If Selection.Value < 0 Then Selection.Font.ColorIndex = 3 Else Selection.Font.ColorIndex = xlAutomatic
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-26 07:30 , Processed in 0.234237 second(s), 8 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表