求助:VBA硬编码条件格式效果时渐变颜色功能失效
硬编码条件格式渐变失效的解决方案求助
现状说明
我找到了一种硬编码条件格式效果的方案,目前能实现颜色和图案的硬编码,但渐变颜色功能无法正常工作。
原始可运行代码
这段代码能正常硬编码条件格式,但仅支持纯色,不支持图案和渐变:
'this block will hard code the applied conditional formatting For Each cell In rng If cell.DisplayFormat.Interior.ColorIndex <> xlNone Then cell.Interior.Color = cell.DisplayFormat.Interior.Color End If Next cell
修改后的代码(渐变部分失效)
新增了图案硬编码功能,但渐变相关代码无法生效,失效段已标记:
'this block will hard code the applied conditional formatting For Each cell In rng If cell.DisplayFormat.Interior.ColorIndex <> xlNone Then With cell.Interior .Color = cell.DisplayFormat.Interior.Color .Pattern = cell.DisplayFormat.Interior.Pattern '*********** THIS BIT DOESN'T WORK************** .Gradient.Degree = cell.DisplayFormat.Interior.Gradient.Degree '.Gradient.ColorStops.Clear With Gradient.ColorStops.Add(0) .Color = cell.DisplayFormat.Interior.Gradient.ColorStops.Add(0).Color .TintAndShade = cell.DisplayFormat.Interior.Gradient.ColorStops.Add(0).TintAndShade End With With Gradient.ColorStops.Add(1) .Color = cell.DisplayFormat.Interior.Gradient.ColorStops.Add(1).Color .TintAndShade = cell.DisplayFormat.Interior.Gradient.ColorStops.Add(1).TintAndShade End With '*********** THIS BIT DOESN'T WORK************** End With End If Next cell
求助需求
恳请提供能正常硬编码渐变颜色的可行解决方案。
内容的提问来源于stack exchange,提问作者Jack Pennington
相关产品推荐
相关产品推荐

