Excel精英培训网

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

求助:求用数字代表颜色的范围?(已解决)

[复制链接]
发表于 2011-7-10 08:26 | 显示全部楼层 |阅读模式
本帖最后由 喜欢学习编程 于 2011-7-10 09:57 编辑

求用数字代表颜色的范围?

Range("a1:c11").Interior.ColorIndex = 5827936

Range("a1:c11").Interior.Color = 5827936 为什么不一样
如果用 Range("a1:c11").Interior.Color 代码来表示,都有哪些数字范围
代表颜色呢?
请高手们写一些用 Range("a1:c11").Interior.Color 代码来表示颜色的数
字范围,谢谢!
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2011-7-10 09:05 | 显示全部楼层
以下改自于别人的代码,供参考:
For myColors = 1 To 56
        Cells(myColors, 1).Interior.ColorIndex = myColors
        Cells(myColors, 2) = myColors
        Cells(myColors, 6) = Cells(myColors, 1).Interior.Color
        HexString = Right("000000" & Hex(Cells(myColors, 1).Interior.Color), 6)
        HTMLcolor = "#" & Right(HexString, 2) & Mid(HexString, 3, 2) & Left(HexString, 2)
        Cells(myColors, 3) = HTMLcolor
        RGBColor = Cells(myColors, 1).Interior.Color Mod 256
        RGBColor = RGBColor & " " & Int(Cells(myColors, 1).Interior.Color / 256) Mod 256
        RGBColor = RGBColor & " " & Int(Cells(myColors, 1).Interior.Color / 256 / 256)
        Cells(myColors, 4) = RGBColor
        ColName = Array("Black", "White", "Red", "Bright Green", "Blue", "Yellow", "Pink", "Turquoise", _
                        "Dark Red", "Green", "Dark Blue", "Dark Yellow", "Violet", "Teal", "Gray-25%", "Gray-50%", "Periwinkle", _
                        "Plum", "Ivory", "Light Turquoise", "Dark Purple", "Coral", "Ocean Blue", "Ice Blue", "Dark Blue", "Pink", _
                        "Yellow", "Turquoise", "Violet", "Dark Red", "Teal", "Blue", "Sky Blue", "Light Turquoise", "Light Green", _
                        "Light Yellow", "Pale Blue", "Rose", "Lavender", "Tan", "Light Blue", "Aqua", "Lime", "Gold", "Light Orange", _
                        "Orange", "Blue-Gray", "Gray-40%", "Dark Teal", "Sea Green", "Dark Green", "Olive Green", "Brown", _
                        "Plum", "Indigo", "Gray-80%")
        COLORNAME = ColName(myColors - 1)
        Cells(myColors, 5) = COLORNAME
    Next
回复

使用道具 举报

发表于 2011-7-10 09:08 | 显示全部楼层
Interior.ColorIndex指的是EXCEL内置索引颜色,只有56种,索引值分别为1~56;并且EXCEL工作表中只能表现出这56种颜色,(没装EXCEL2007,2010不太清楚)
而Interior.Color(本身是变体类型)的颜色是由RGB函数返回的long值数据决定的。取值范围是0~256的3次方。超过这个范围的值,也不会报错,但并没有与之对应的颜色值。根据某种算法,它会自动修改为可识别的对应颜色值。
回复

使用道具 举报

 楼主| 发表于 2011-7-10 09:57 | 显示全部楼层
谢谢老师的帮助,我后来用查看的方式,用RBG(,,)的方法解决了。
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-29 04:45 , Processed in 0.536174 second(s), 6 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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