由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
WashingtonDC版 - can anyone help me with a vba code? (you bao zi) (转载)
相关主题
请推荐rockville/bethesda一带dim sum餐馆好奇地问一下北京,学会oracle的salary range大概多少?
請推薦在DC的吃你们说一口气看五六十套房子怎么做到的?
DC-Baltimore附近哪里有比较好的Dim Sum?Island Range Hood 抽油烟机 - 包子
Recommendation for Dim Sum?偶Out啦,20出头是在哪个年龄Range?
想吐MD和VA 的gun range 要permit吗?
Dim Sum 哪好啊?应该什么时间去呢?买了个gas range,怎么找人安装便宜?
Ping Pong Dim Sum in Chinatown and Dupont CircleRe: 请问hyattsville附近有没有好的法国餐馆或意大利餐馆
石家庄有什么好的粤菜馆吗?请问:关于申请MD的ID Card
相关话题的讨论汇总
话题: range话题: color话题: end话题: set话题: rng
进入WashingtonDC版参与讨论
1 (共1页)
V******n
发帖数: 881
1
【 以下文字转载自 CS 讨论区 】
发信人: VAMclean (Mclean), 信区: CS
标 题: can anyone help me with a vba code? (you bao zi)
发信站: BBS 未名空间站 (Fri Jan 10 16:48:07 2014, 美东)
Sub Testing()
' Fill a range with numbers from 1 to 256.
Dim rng As Range
Set rng = Range("BF4:BF256")
Range("BF4") = 1
Range("BF5") = 2
Range("BF4:BF5").AutoFill Destination:=rng



' Add a 2-color scale.
Dim cs As ColorScale
Set cs = rng.FormatConditions.AddColorScale(ColorScaleType:=2)
' Format the first color as red
With cs.ColorScaleCriteria(1)
.Type = xlConditionValueLowestValue
With .FormatColor
.Color = vbRed
' TintAndShade takes a value between -1 and 1.
' -1 is darkest, 1 is lightest.
.TintAndShade = 0
End With
End With

' Format the second color as green, at the highest value.
With cs.ColorScaleCriteria(2)
.Type = xlConditionValueHighestValue
With .FormatColor
.Color = vbGreen
.TintAndShade = 0
End With
End With

' Try again with a rectangular range of values.
' Lowest values should be red, values at the 50th percentile
' should be red/green, high values are green.
Set rng = Range("v4", "ak19")
rng.FormatConditions.Delete
Set cs = rng.FormatConditions.AddColorScale(ColorScaleType:=3)

' Set the color of the lowest value, with a range up to
' the next scale criteria. The color should be red.
With cs.ColorScaleCriteria(1)
.Type = xlConditionValueLowestValue
With .FormatColor
.Color = vbRed
.TintAndShade = 0
End With
End With


' At the 50th percentile, the color should be yellow.
' Note that you cannot set the Value property for all
' values of Type.
With cs.ColorScaleCriteria(2)
.Type = xlConditionValuePercentile
.Value = 50
With .FormatColor
.Color = vbYellow
.TintAndShade = 0
End With
End With

' At the highest value, the color should be green.
With cs.ColorScaleCriteria(3)
.Type = xlConditionValueHighestValue
With .FormatColor
.Color = vbGreen
.TintAndShade = 0
End With
End With


' Add hide font color
Dim cell As Variant

'Dim rng As Range

Set rng = Range("v4:ak19")
For Each cell In Selection
cell.Font.Color = cell.Interior.Color
Next
End Sub
"
the last segment somehow doesn't work. please help! thanks and bao zi feng
shang!
Set rng = Range("v4:ak19")
For Each cell In Selection
cell.Font.Color = cell.Interior.Color
Next
x*******a
发帖数: 11067
2
rng.Font.Color = rng.Interior.Color
V******n
发帖数: 881
3
lao da
it needs to be in a loop and this one will create bugs...

【在 x*******a 的大作中提到】
: rng.Font.Color = rng.Interior.Color
x*******a
发帖数: 11067
4
你不就是想把那个区域的文字用背景颜色覆盖?这样跑不过去吗?不需要loop啊。

【在 V******n 的大作中提到】
: lao da
: it needs to be in a loop and this one will create bugs...

V******n
发帖数: 881
5
sorry i can't type chinese on this computer
background has conditional formatting created scaled colors, green in the
lower right corner and gradually moves to red in the upper left corner.
cell.Font.Color = cell.Interior.Color
the micro runs through but i can still see the numbers (font) after I
overwrote it using the interior color. somehow the font color only has 2
types, green or red, not scaled at all...

【在 x*******a 的大作中提到】
: 你不就是想把那个区域的文字用背景颜色覆盖?这样跑不过去吗?不需要loop啊。
n*****r
发帖数: 1087
6
Set rng = Range("v4:ak19")
For Each cell In Selection
我觉得是这两行有点问题,问题可能不在cell.Font.Color = cell.Interior.Color这
个loop里,可能你的selection不是rng这个range,compile时最好用step into一行一
行检查一下,容易发现哪里出了问题。
要不把第一行改改试试。
Range("v4:ak19").Select
For Each cell In Selection
如果说错了,当我没说。
n*****r
发帖数: 1087
7
应该跑不过去,每个cell的background color有自己的value,即使background color
都一样,应该还是跑步过去。

【在 x*******a 的大作中提到】
: 你不就是想把那个区域的文字用背景颜色覆盖?这样跑不过去吗?不需要loop啊。
V******n
发帖数: 881
8
我那个原始的code能跑过去
但font没覆盖住
而且我用cell.Font.Color=vbblue 试过也跑过去了,所有font都变成vbblue了
但是cell.Font.Color = cell.Interior.Color 就是盖不住
好像因为是conditional formatting,这个interior color不是渐进的color

【在 n*****r 的大作中提到】
: 应该跑不过去,每个cell的background color有自己的value,即使background color
: 都一样,应该还是跑步过去。

n*****r
发帖数: 1087
9
http://www.cpearson.com/excel/CFColors.htm
不知道这个link对你有没有用,cell.Font.Color=vbblue 行的话,那可能就是
Interior.Color 没能读出你想要的color value。这么说,如果background color是
conditional formatting,Interior.Color 这个写法是读不出来的。
Unfortunately, the Color and ColorIndex properties of a Range don't return
the color of a cell that is displayed if Conditional formatting is applied
to the cell. Nor does it allow you to determine whether a conditional
format is currently in effect for a cell.
V******n
发帖数: 881
10
thanks, the functions didn't work
but I found an alternative way to resolve it. I hid the numbers...
already sent bao zi to the 2 friends above.

【在 n*****r 的大作中提到】
: http://www.cpearson.com/excel/CFColors.htm
: 不知道这个link对你有没有用,cell.Font.Color=vbblue 行的话,那可能就是
: Interior.Color 没能读出你想要的color value。这么说,如果background color是
: conditional formatting,Interior.Color 这个写法是读不出来的。
: Unfortunately, the Color and ColorIndex properties of a Range don't return
: the color of a cell that is displayed if Conditional formatting is applied
: to the cell. Nor does it allow you to determine whether a conditional
: format is currently in effect for a cell.

1 (共1页)
进入WashingtonDC版参与讨论
相关主题
请问:关于申请MD的ID Card想吐
谁知道DC附近比较好的中国海鲜自助?要去开会,想吃顿crab leg.Dim Sum 哪好啊?应该什么时间去呢?
Mao Tai liquor available in DC?Ping Pong Dim Sum in Chinatown and Dupont Circle
Excel 2007 Conditional Formatting石家庄有什么好的粤菜馆吗?
请推荐rockville/bethesda一带dim sum餐馆好奇地问一下北京,学会oracle的salary range大概多少?
請推薦在DC的吃你们说一口气看五六十套房子怎么做到的?
DC-Baltimore附近哪里有比较好的Dim Sum?Island Range Hood 抽油烟机 - 包子
Recommendation for Dim Sum?偶Out啦,20出头是在哪个年龄Range?
相关话题的讨论汇总
话题: range话题: color话题: end话题: set话题: rng