我试图对Excel图表上的最大和最小数字进行颜色编码。遵循Peltiertech.com的想法,我有一个可行的代码。但问题是Excel中的数字格式化为无小数点(FormulaRange4.NumberFormat =“0”)。通过我的VBA公式检出的值不是格式化的。因此,我的“min”被读为265.875,而不是四舍五入的266.因此,代码无法找到我的最小值。VBA格式化条件格式化循环中的数字
有没有人有解决这个问题?以下是代码。子例程是相当大的,但是关注的部分用 “”子wiseowltutorial()“
Set FormulaRange3 = .Range(.Cells(d, c + 2), .Cells(r - 1, c + 3))
FormulaRange3.NumberFormat = "0"
Set FormulaRange4 = .Range(.Cells(d, c + c + 3), .Cells(r - 1, c + c + 3))
FormulaRange4.NumberFormat = "0"
Set SelectRanges = Union(FormulaRange3, FormulaRange4)
SelectRanges.Select
ActiveSheet.Shapes.AddChart.Select
With ActiveChart
.Type = xlColumn
.HasTitle = True
.ChartTitle.Text = "Individual Employee Productivity"
.ChartTitle.Font.Bold = True
.Axes(xlCategory).HasTitle = True
.Axes(xlCategory).AxisTitle.Text = "Employees"
.Axes(xlValue).HasTitle = True
.Axes(xlValue).AxisTitle.Text = "Widgets Produced"
.Axes(xlValue).MajorGridlines.Delete
.ApplyDataLabels
.Legend.Delete
.Parent.Name = "Individual Employee Productivity"
结束随着
结束随着 '开始结束子
'子fromYouTubewiseowltutorial() '找到正确的方法来突出显示每个团队中最具生产力的人或最差的人
Dim ppApp As PowerPoint.Application
Dim ppPres As PowerPoint.Presentation
Dim ppSlide As PowerPoint.Slide
Dim ppTextbox As PowerPoint.Shape
Dim ppiPoint As Long
Dim ppvValues As Variant
Dim pprValue As Range
Dim lMax As Long
lMax = WorksheetFunction.Max(FormulaRange4)
Dim lMin As Long
lMin = WorksheetFunction.Min(FormulaRange4)
With ActiveChart.SeriesCollection(1)
ppvValues = .Values
For ppiPoint = 1 To UBound(ppvValues)
If ppvValues(ppiPoint) = lMax Then
.Points(ppiPoint).Format.Fill.ForeColor.RGB = RGB(0, 225, 0)
End If
If ppvValues(ppiPoint) = lMin Then
.Points(ppiPoint).Format.Fill.ForeColor.RGB = RGB(225, 0, 0)
End If
Next
End With
谢谢:)
使用条件格式和最小/最大功能是什么? –
hi @KoebmandSTO我该怎么做?你有一个适合我当前代码的代码示例吗?一切都需要自动化和动态 - 无法手动完成。谢谢 – Jonh
条件格式化不在VBA中完成。单击条件格式, - >根据公式,选择您想要的颜色,并输入条件,如= IF(ROUND(A1; 0)= ROUND(MIN(A1:A100); 0); TRUE; FALSE) (修改它以适应您的确切需求)。 –