Selamlar,
Excel'de makro ile beraber kullanıcıdan yıl ve sayısal(kâr) inputu alarak bir zaman serisi grafiği çıktı vermem gerekiyor.
İlk sheet içerisinde 2 kolon olacak: yıl ve kar miktarı diye.
İkinci sheet içerisine de grafiklerin gelmesi lazım.
2 adet tuş olacak şekilde yapmalıyım bunu.
Veri Girişi ve Grafikle Göster olacak şekilde.
Veri Girişi tuşuna her basıldığında A2:A300 aralığına yalnızca bilgisi, B2:B300 kısmına ise sadece sayısal değer eklenecek.
Grafikle Göster butonuna tıkladığı anda x ekseninde Yıl, y ekseninde de Kar Miktarı olacak bir grafik çıkması gerekiyor.
Bu makroyu yazmamda bana yardımcı olabilecek birisi var mı?
Kod
Excel'de makro ile beraber kullanıcıdan yıl ve sayısal(kâr) inputu alarak bir zaman serisi grafiği çıktı vermem gerekiyor.
İlk sheet içerisinde 2 kolon olacak: yıl ve kar miktarı diye.
İkinci sheet içerisine de grafiklerin gelmesi lazım.
2 adet tuş olacak şekilde yapmalıyım bunu.
Veri Girişi ve Grafikle Göster olacak şekilde.
Veri Girişi tuşuna her basıldığında A2:A300 aralığına yalnızca bilgisi, B2:B300 kısmına ise sadece sayısal değer eklenecek.
Grafikle Göster butonuna tıkladığı anda x ekseninde Yıl, y ekseninde de Kar Miktarı olacak bir grafik çıkması gerekiyor.
Bu makroyu yazmamda bana yardımcı olabilecek birisi var mı?
Kod
Kod:
Sub ZamanSerisiGrafigi()
Dim wsData As Worksheet
Dim wsChart As Worksheet
Dim chartObj As ChartObject
Dim dataRange As Range
Dim chartRange As Range
Dim lastRow As Long
Set wsData = ThisWorkbook.Sheets("Sheet1")
Set wsChart = ThisWorkbook.Sheets("Sheet2")
lastRow = wsData.Cells(wsData.Rows.Count, "A").End(xlUp).Row
Dim yearInput As String
Dim profitInput As Double
Dim insertRow As Long
Do
yearInput = InputBox("Lütfen bir yıl girin (1900-2023 arası):")
Loop Until IsNumeric(yearInput) And yearInput >= 1900 And yearInput <= 2023
Do
profitInput = InputBox("Lütfen kar miktarını girin:")
Loop Until IsNumeric(profitInput)
insertRow = wsData.Cells(lastRow, "A").Row + 1
With wsData
.Cells(insertRow, "A").Value = yearInput
.Cells(insertRow, "B").Value = profitInput
.Range("A1:B" & insertRow).Sort Key1:=.Range("A2"), Order1:=xlAscending, Header:=xlYes
End With
Set dataRange = wsData.Range("A2:B" & lastRow + 1)
Set chartObj = wsChart.ChartObjects.Add(Left:=10, Width:=375, Top:=10, Height:=225)
Set chartRange = dataRange.Offset(1).Resize(lastRow)
With chartObj.Chart
.ChartType = xlLine
.SeriesCollection.NewSeries
.SeriesCollection(1).Name = wsData.Range("B1").Value
.SeriesCollection(1).xValues = dataRange.Columns(1)
.SeriesCollection(1).Values = dataRange.Columns(2)
.HasTitle = True
.ChartTitle.Text = "Zaman Serisi Grafiği"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Text = wsData.Range("A1").Value
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Text = wsData.Range("B1").Value
End With
With chartObj
.Width = 395
.Height = 280
.Left = wsChart.Range("A1").Left
.Top = wsChart.Range("A1").Top
End With
yearInput = ""
profitInput = 0
wsData.Range("C1").Value = "Evet"
End Sub
Sub VeriGirisi_Click()
Call ZamanSerisiGrafigi
End Sub
Sub GrafikleGoster_Click()
ThisWorkbook.Sheets("Sheet2").Activate
End Sub
Sub TumVeriyiSil_Click()
Dim wsData As Worksheet
Dim lastRow As Long
Set wsData = ThisWorkbook.Sheets("Sheet1")
With wsData
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
If lastRow > 1 Then
.Range("A2:B" & lastRow).ClearContents
End If
.Range("C1").Value = ""
End With
End Sub
Son düzenleme: