只想更改E和B列的线条颜色,这是我的代码:
Sub HistoricalProdUnitAndDemand()
' Creates a line chart for the demand column
Worksheets("DATA").Activate
' Doesn't work because it is looking for a Worksheet not a SHEET WTF
For Each Ws In Sheets
If Ws.Name = "Production VS Demand" Then
Application.DisplayAlerts = False
Sheets("Production VS Demand").Delete
Application.DisplayAlerts = True
Exit For
End If
Next
Columns("A:A").Select
Selection.NumberFormat = "[$-en-US]mmm-yy;@"
' This formats column A to be in the proper date format of mmm-yy
Range("A:A,E:E,B:B").Select
ActiveSheet.Shapes.AddChart2(332, xlLineMarkers).Select
ActiveChart.SetSourceData Source:=Range("A:A,E:E,B:B")
ActiveChart.Location Where:=xlLocationAsNewSheet, Name:="Production VS Demand"
' Places line chart in a new worksheet called Production VS Demand
ActiveChart.Axes(xlCategory).Select
Selection.TickLabels.Orientation = 70
Selection.MajorTickMark = xlNone
ActiveChart.ChartTitle.Select
ActiveChart.ChartTitle.Text = "Production VS Demand"
' Adds in the chart's title
ActiveChart.SetElement (msoElementLegendRight)
' Adds in the chart's legend to the right
Selection.Format.TextFrame2.TextRange.Characters.Text = "Production VS Demand"
With Selection.Format.TextFrame2.TextRange.Characters(1, 20).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
ActiveChart.ChartArea.Select
End Sub
答案 0 :(得分:0)
您可以创建它:
Sub setColor(HexColors As Long)
Range("E").Interior.Color = HexColors
Range("B").Interior.Color = HexColors
end sub
然后,您可以在Sub HistoricalProdUnitAndDemand()中放置一行,如下所示:
HistoricalProdUnitAndDemand()
[...]
setColor 49407
[...]
end sub
您可以在互联网上查找自己的十六进制颜色(49407代表“金黄色”或类似的颜色)
再见,祝您愉快!