我正在做一些小事,以减少工作量。 我决定,由于使用VB进行频繁的数据刷新将是恒定格式化和清除单元格的最佳分辨率。我已经有5年没有接触VB了,我不明白为什么这不起作用。
该代码应该可以工作,我将其检查为不同的按钮,但是在进行某些复制和粘贴之后,条件格式不起作用。
Set rng = Range("B1:B15")
rng.Clear
'Formating Data with color to Value
Selection.FormatConditions.AddColorScale ColorScaleType:=3
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
Selection.FormatConditions(1).ColorScaleCriteria(1).Type = xlConditionValueLowestValue
With Selection.FormatConditions(1).ColorScaleCriteria(1).FormatColor
.Color = 8109667
.TintAndShade = 0
End With
代码应清空单元格B1至B15并对其进行格式化,以根据值更改颜色。它只是颜色格式化的唯一部分,我不想放入所有24行代码。
答案 0 :(得分:1)
您的问题尚不清楚,但是Clear
和ClearContents
之间有细微差别
Range.Clear
清除Range
对象中的所有公式和格式 Range.CearContents
清除单元格的内容(值),但保留格式不变因此,请确保您使用的是正确的,即使有必要也可以使用两者,avoid Select
altogether也是个好主意。就您而言,Selection
仅在用户在工作表中选择特定的Range
时有效。
似乎您可能想将格式应用于rng
对象
rng.FormatConditions.AddColorScale ColorScaleType:=3 'and so on..