我試圖對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) (修改它以適應您的確切需求)。 –