2016-07-07 66 views
0

我創建了一系列列圖,顯示一個度量標準上每個ID的性能,但希望突出顯示屬於另一個相關度量標準的最佳執行者的列。我沒有關於相關指標的數據,只有一個列表(在Excel中,在同一張表上)是最佳表現者的ID。使用VBA根據數組中的ID值更改條的顏色

使用條件格式可以輕鬆地突出顯示頂級執行者列表中包含的ID,但是我還想更改列圖中這些ID的列的顏色,而無需手動單擊以更改每個列的顏色。

此代碼(來自this寶貴的線程)似乎應該能夠做我在找的東西,但我不熟悉VBA以瞭解如何將數組放入if條件或應用它到工作表/工作簿中的所有圖表。

Dim c As Chart 
Dim s As Series 
Dim iPoint As Long 
Dim nPoint As Long 

Set c = ActiveChart 
Set s = c.SeriesCollection(1) 

nPoint = s.Points.Count 
For iPoint = 1 To nPoint 
    If s.XValues(iPoint) = "avg" Then 
     s.Points(iPoint).Interior.Color = RGB(255, 0, 0) 
    End If 
Next iPoint 

我是塔塔/ SAS程序員,而不是過於熟悉VBA,但我相信,像

local list=R26C2:R26C12 

foreach worksheet in (all worksheets) {  
    foreach bar in (all_graphs of &worksheet) { 
     color &bar=blue if id in(&list) 
    } 
} 

不應該給我,我在試圖儘可能多的麻煩在VBA中執行此操作。任何幫助,將不勝感激。謝謝!

回答

1

像這樣的東西應該工作(未經測試)

Dim rngTP As Range 
Set rngTP = Range("A1:A10") 'for example 

nPoint = s.Points.Count 
For iPoint = 1 To nPoint 
    If Not IsError(Application.Match(s.XValues(iPoint), rngTP, 0)) Then 
     s.Points(iPoint).Interior.Color = RGB(255, 0, 0) 
    End If 
Next iPoint 
+0

這個偉大的工程!非常感謝。 – Rob