Я хочу изменить цвет каждой серии в зависимости от значения ячейки на другом листе.
Я проверил, шагая по макросу, и все, кроме изменения цвета, работает. Этот тип кода будет запускаться шесть раз для различных типов событий (я удалил пять событий, чтобы сократить длину этого сообщения).
У меня нет маркеров ни в одной из серий, только для подключения линия между двумя точками этой серии.
Снимок экрана графика.
Sub test()
Dim LastRowB As Long
Dim LastRowJ As Long
Dim LastRowR As Long
Dim LastRowZ As Long
Dim LastRowAH As Long
Dim LastRowAP As Long
Dim chartj As Variant
Dim wb As Workbook
Dim ws As Worksheet
Set ws6 = Sheet6
'Set chart axis to approximately the range required
Chart7.Axes(xlCategory).MinimumScale = 43000
Chart7.Axes(xlCategory).MaximumScale = 44500
'Set graph ranges as per sheet
Chart7.Axes(xlCategory).MinimumScale = ws6.Range("D9").Value
Chart7.Axes(xlCategory).MaximumScale = ws6.Range("D10").Value
'All subsequent examples follow template for fills
'--------------------------- Fill ------------------------------
'Find first occurence of -. There should be a - under all arrays to ensure that a stop ocurs or this will get stuck in a loop if all entries are filled
'i.e. 15 fill batches are performed and no - will appear in the table.
LastRowB = ws6.Cells.Find(What:="-", _
After:=ws6.Range("B15"), _
LookAt:=xlWhole, _
LookIn:=xlValues, _
searchorder:=xlByColumns, _
searchdirection:=xlNext, _
MatchCase:=False).Row
' Set the integers j = 1 and runs all loops up until a max of 15 occurences based off of i. This is cause there are 15 Fills series plotted on the graph.
' i = 16 as arrays start in row 16. And this runs until the number of row that the last dash is found.
Dim i As Integer
Dim j As Integer
j = 1
For i = 16 To LastRowB
If i = LastRowB Then
'if we have hit the last row number then we end the if and move on
Else
Set chartj = Chart7.SeriesCollection(j)
chartj.Select
'This .select is to confirm that the correct series is being selected. Can be removed.
'Check to see if the series should be green or red colour from the colour column
If ws6.Range("F" & i).Value = "Green" Then
'Format the connecting lines as green
chartj.Format.Line.Visible = msoFalse
chartj.Format.Line.Visible = msoTrue
chartj.Border.LineStyle = xlContinuous
chartj.Border.Color = RGB(0, 176, 80)
Else
'Format the connecting lines as red
chartj.Format.Line.Visible = msoFalse
chartj.Format.Line.Visible = msoTrue
chartj.Border.LineStyle = xlContinuous
chartj.Border.Color = RGB(255, 0, 0)
End If
End If
j = j + 1
Next i
Excel 2013 в Windows 10.