두 개의 데이터 열에서 차트를 생성하려는 기능에 대한 도움이 필요합니다. 첫 번째 열에는 매달 약 1 개씩 날짜가 포함되고 두 번째 열에는 해당 날짜 (가스 사용량)에 대한 데이터가 포함됩니다. 나는 차트가 매년 별도의 선 시리즈가있는 선 그래프가되기를 원합니다 (괜찮습니다). 데이터가 월 단위이고 1 월부터 12 월까지 실행되므로 포인트를 월 단위로 지정하고 싶습니다.
내가 지금 겪고있는 문제는 맨 아래 축이 나열된 첫 번째 달 (샘플 사진의 11 월)에서 실행되고 판독 값이 두 번 이상 취해 졌기 때문에 일부 달이 두 번 이상 나열되기 때문에 12 개월 이상을 포함한다는 것입니다. 달. 결국 나는 이것들을 한 달에 하나의 값으로 합산하기를 원하지만 나중에 그것을 계산할 것입니다. 또한 값이 옆에있는 열의 달과 일치하지 않는 것 같지만 나열된 순서대로 이동합니다.
다음은 시트 및 현재 차트의 샘플 사진에 대한 링크입니다.
내 현재 코드는 다음과 같습니다.
'These dates will be compared to see if the year has changed
NextDate = ActiveCell.Value
LastDate = ActiveCell.Value
j = 5
K = 1
'Makes the linechart
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlLineMarkers
'For some reason a bunch of series are made automatically
'Delete all those garbage series...
For Each s In ActiveChart.SeriesCollection
s.Delete
Next s
'I have a function that already found the last row and assigned it to LastRow... So this runs through all of column A, checks if the years are different and makes a series when the years are different
For i = 5 To (LastRow)
NextDate = ActiveCell.Offset(i - 5, 0).Value
If (Year(LastDate) <> Year(NextDate)) Or (i = LastRow) Then
'The series starts at value after the end of the last
'series, or at row 5
Set rngRange = ActiveSheet.Range(Cells(j, 1), Cells(i, 1))
'K counts up for every series made, starting at 1
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(K).Name = "=""" & Year(LastDate) & """"
ActiveChart.SeriesCollection(K).Values = rngRange.Offset(0, 4)
'Right now I have a function which copies the months into column H.
'Later I'll get it to just use the dates and change the axis to months I think
ActiveChart.SeriesCollection(K).XValues = rngRange.Offset(0, 7)
'Stop
j = i
K = K + 1
LastDate = NextDate
End If
Next i
ActiveChart.ChartStyle = 34
ActiveChart.ApplyLayout (1)
ActiveChart.Axes(xlCategory).CategoryType = xlCategoryScale
ActiveChart.ClearToMatchStyle
도와 주셔서 감사합니다. 제 코드가 이해되기를 바랍니다. 나는 나 가면서 배우고있다.
날짜 및 사용량 값의 피벗 테이블을 만듭니다. 행 영역에 날짜를 입력하고 데이터 영역에 사용량 합계를 입력합니다. 그런 다음 연도와 월별로 날짜를 그룹화하고 연도를 열 영역으로 이동합니다. 피벗 테이블의 차트를 만듭니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다