使用循环自动调整 Excel 图表线宽
Auto Adjust Excel Chart Line Weights With a Loop
我正在尝试调整 Excel 图表上的线条粗细(或粗细)。我希望每条线的粗细都根据我保存在命名范围 "Weights"
中的权重进行调整
我无法正确处理这个双循环
我有循环 VBA 循环,但目前它会将每个图表系列调整为我的 "Weights" 系列中的所有每个值,然后继续循环到下一个 Srs。我希望我的 Srs 中的每个值只更改一次,然后 select 下一个权重。
当我尝试将循环强制到下一个 "Srs" 时,我得到了 'Invalid next control variable reference'
这个双循环需要如何构建才能将每条线(Srs)调整到我的每个权重(£w)
谢谢
Sub SetWeights()
Dim Srs As Series
Dim myWeight As Range
Dim £w As Range
Set myWeight = Range("Weights")
With ActiveSheet
For Each Srs In ActiveChart.SeriesCollection
For Each £w In myWeight
Srs.Format.Line.Weight = £w
'Debug.Print £w
Next 'Srs
Next '£w
End With
End Sub
这是您正在尝试的吗?
Sub SetWeights()
Dim Srs As Series
Dim myWeight As Range
Dim £w As Range
Dim j As Long
Set myWeight = Range("Weights")
j = 1
With ActiveSheet
For Each £w In myWeight
If j > ActiveChart.SeriesCollection.Count Then Exit Sub
ActiveChart.SeriesCollection(j).Format.Line.Weight = £w
j = j + 1
Next £w
End With
End Sub
我正在尝试调整 Excel 图表上的线条粗细(或粗细)。我希望每条线的粗细都根据我保存在命名范围 "Weights"
中的权重进行调整我无法正确处理这个双循环
我有循环 VBA 循环,但目前它会将每个图表系列调整为我的 "Weights" 系列中的所有每个值,然后继续循环到下一个 Srs。我希望我的 Srs 中的每个值只更改一次,然后 select 下一个权重。
当我尝试将循环强制到下一个 "Srs" 时,我得到了 'Invalid next control variable reference'
这个双循环需要如何构建才能将每条线(Srs)调整到我的每个权重(£w)
谢谢
Sub SetWeights()
Dim Srs As Series
Dim myWeight As Range
Dim £w As Range
Set myWeight = Range("Weights")
With ActiveSheet
For Each Srs In ActiveChart.SeriesCollection
For Each £w In myWeight
Srs.Format.Line.Weight = £w
'Debug.Print £w
Next 'Srs
Next '£w
End With
End Sub
这是您正在尝试的吗?
Sub SetWeights()
Dim Srs As Series
Dim myWeight As Range
Dim £w As Range
Dim j As Long
Set myWeight = Range("Weights")
j = 1
With ActiveSheet
For Each £w In myWeight
If j > ActiveChart.SeriesCollection.Count Then Exit Sub
ActiveChart.SeriesCollection(j).Format.Line.Weight = £w
j = j + 1
Next £w
End With
End Sub