VBA 条件格式数据栏 "Percent/Progress"
VBA Conditional Formatting Data Bar "Percent/Progress"
基本上,我正在尝试这样做:
(三张图片)
所以我录制了一个宏(打算稍后清理它!)我希望单元格数据栏基本上是单元格中百分比的大小。
我收到这个录音。
Range("H439:H445").Select
Selection.FormatConditions.AddDatabar
Selection.FormatConditions(Selection.FormatConditions.Count).ShowValue = True
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1)
.MinPoint.Modify newtype:=xlConditionValueLowestValue
.MaxPoint.Modify newtype:=xlConditionValueHighestValue
End With
With Selection.FormatConditions(1).BarColor
.Color = 49407
.TintAndShade = 0
End With
Selection.FormatConditions(1).BarFillType = xlDataBarFillSolid
Selection.FormatConditions(1).Direction = xlContext
Selection.FormatConditions(1).NegativeBarFormat.ColorType = xlDataBarColor
Selection.FormatConditions(1).BarBorder.Type = xlDataBarBorderNone
With Selection.FormatConditions(1).NegativeBarFormat.Color
.Color = 255
.TintAndShade = 0
End With
我从录音中多次收到此代码,但在搜索答案后我意识到这是一个 excel 错误或 problem/error。但是我觉得我的问题是 xlConditionValueHighestValue (和最低)部分。记录的代码的另一部分显示 xlAutomaticMax/xlAutomaticMin 在它的位置。
当我 运行 代码的一部分(已发布的部分)时,它不会根据我输入的 Max/Min 值 (1, 0) 进行填充。相反,它采用最高数字(在本例中为 33%)并一直填充该单元格。
当我将该部分更改为:
With Selection.FormatConditions(1)
.MinPoint.Modify newtype:=0
.MaxPoint.Modify newtype:=1
End With
我得到一个
“运行-时间错误'1004':
应用程序定义或对象定义的错误”
突出显示
.MaxPoint.Modify newtype:=1
行,所以它喜欢0行。但是我不知道正确的编码程序来让它做我想做的事,而且我在论坛上没有找到任何使用 maxpoint 或 minpoint 公式行的东西,否则我会尝试复制他们的符号。有人知道如何提供帮助吗?
请尝试:
With Selection.FormatConditions(1)
.MinPoint.Modify newtype:=xlConditionValueNumber, newvalue:=0
.MaxPoint.Modify newtype:=xlConditionValueNumber, newvalue:=1
End With
或者,您可以坚持现有的,但包括一个值为 1
.
的隐藏行
基本上,我正在尝试这样做:
(三张图片)
所以我录制了一个宏(打算稍后清理它!)我希望单元格数据栏基本上是单元格中百分比的大小。
我收到这个录音。
Range("H439:H445").Select
Selection.FormatConditions.AddDatabar
Selection.FormatConditions(Selection.FormatConditions.Count).ShowValue = True
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1)
.MinPoint.Modify newtype:=xlConditionValueLowestValue
.MaxPoint.Modify newtype:=xlConditionValueHighestValue
End With
With Selection.FormatConditions(1).BarColor
.Color = 49407
.TintAndShade = 0
End With
Selection.FormatConditions(1).BarFillType = xlDataBarFillSolid
Selection.FormatConditions(1).Direction = xlContext
Selection.FormatConditions(1).NegativeBarFormat.ColorType = xlDataBarColor
Selection.FormatConditions(1).BarBorder.Type = xlDataBarBorderNone
With Selection.FormatConditions(1).NegativeBarFormat.Color
.Color = 255
.TintAndShade = 0
End With
我从录音中多次收到此代码,但在搜索答案后我意识到这是一个 excel 错误或 problem/error。但是我觉得我的问题是 xlConditionValueHighestValue (和最低)部分。记录的代码的另一部分显示 xlAutomaticMax/xlAutomaticMin 在它的位置。
当我 运行 代码的一部分(已发布的部分)时,它不会根据我输入的 Max/Min 值 (1, 0) 进行填充。相反,它采用最高数字(在本例中为 33%)并一直填充该单元格。 当我将该部分更改为:
With Selection.FormatConditions(1)
.MinPoint.Modify newtype:=0
.MaxPoint.Modify newtype:=1
End With
我得到一个 “运行-时间错误'1004': 应用程序定义或对象定义的错误” 突出显示
.MaxPoint.Modify newtype:=1
行,所以它喜欢0行。但是我不知道正确的编码程序来让它做我想做的事,而且我在论坛上没有找到任何使用 maxpoint 或 minpoint 公式行的东西,否则我会尝试复制他们的符号。有人知道如何提供帮助吗?
请尝试:
With Selection.FormatConditions(1)
.MinPoint.Modify newtype:=xlConditionValueNumber, newvalue:=0
.MaxPoint.Modify newtype:=xlConditionValueNumber, newvalue:=1
End With
或者,您可以坚持现有的,但包括一个值为 1
.