excel 如何实现.IncrementLeft 360来显示相邻的图形?

6pp0gazn  于 2023-11-20  发布在  其他
关注(0)|答案(1)|浏览(97)

如何在下面的代码中实现.IncrementLeft 360,使图形不会堆叠在一起?我需要它们彼此相邻。

Sub AddChartsTemplate()
Dim i As Integer 'rows
Dim j As Integer 'columns

i = Cells(Rows.Count, 2).End(xlUp).Row

For j = 5 To 9
    With ActiveSheet.Shapes.AddChart.Chart
        .ChartType = xlLine
        .SeriesCollection.NewSeries
        With .SeriesCollection(1)
            .XValues = "=" & ActiveSheet.Name & "!" & _
              Range(Cells(12, 2), Cells(i, 2)).Address
            .Name = "=" & ActiveSheet.Name & "!" & _
              Cells(10, j).Address
            .Values = "=" & ActiveSheet.Name & "!" & _
              Range(Cells(12, j), Cells(i, j)).Address
        End With
    '    .HasLegend = False
    End With
Next j

End Sub

字符串

5t7ly7z5

5t7ly7z51#

你可以这样做:

Sub AddChartsTemplate()
    Dim i As Long, j As Long, lft As Long
    Dim co As Object, ws As Worksheet
    
    Set ws = ActiveSheet
    
    lft = 10            'left start postion
    i = ws.Cells(ws.Rows.Count, 2).End(xlUp).Row
    
    For j = 5 To 9
        
        Set co = ws.Shapes.AddChart   'add chartobject
        co.Top = 50     'for example
        co.Left = lft   'set left
        lft = lft + 360 'increment left position
        
        With co.Chart
            .ChartType = xlLine
            With .SeriesCollection.NewSeries
                'add quotes in case worksheet name has a sapce...
                .XValues = "='" & ws.Name & "'!" & _
                                ws.Range(ws.Cells(12, 2), ws.Cells(i, 2)).Address
                .Name = "='" & ws.Name & "'!" & ws.Cells(10, j).Address
                .Values = "='" & ws.Name & "'!" & _
                                ws.Range(ws.Cells(12, j), ws.Cells(i, j)).Address
            End With
       End With
    Next j
End Sub

字符串

相关问题