Hello,
I have made three buttons that make histograms which work. I wrote my code so that the plots are each placed in a specific location. However, if I click another button to get a separate chart, it is plotted on top of the other histogram, and both are moved to the location of the newly made histogram.
Here is my code for one of the histograms. The other codes are pretty much the same. I have it so that if I ask to make a new histogram, the old histogram (with the same title) is deleted.
Thank you.
Dim binStartHVBD As Double
Dim binEndHVBD As Double
Dim binWidthHVBD
Dim numberOfBinHVBD As Double
Dim i As Double
Dim hvbdRange As Range
Dim binRange As Range
Dim cht As ChartObject
binStartHVBD = Cells(3, 9).Value
binEndHVBD = Cells(4, 9).Value
binWidthHVBD = Cells(5, 9).Value
numberOfBinsHVBD = ((binEndHVBD - binStartHVBD) / binWidthHVBD) + 11
Cells(11, 9) = binStartHVBD
For i = 12 To numberOfBinsHVBD
Cells(i, 9) = Cells(i - 1, 9).Value + binWidthHVBD
Next i
Set hvbdRange = Range("B11", Range("B" & Rows.Count).End(xlUp))
Set binRange = Range("I11", Cells(numberOfBinsHVBD, 9))
Columns(53).ClearContents
Columns(54).ClearContents
Dim outputRange As Range
Set outputRange = ActiveSheet.Range("BA1")
For Each cht In ActiveSheet.ChartObjects
If cht.Chart.HasTitle And cht.Chart.ChartTitle.Text = "X" Then
cht.Delete
End If
Next cht
Application.Run "ATPVBAEN.XLAM!Histogram", hvbdRange, outputRange, binRange, False, False, True, _
False
ActiveChart.ChartTitle.Text = "X"
ActiveChart.Axes(xlCategory, xlPrimary).AxisTitle.Text = "X"
For Each cht In ActiveSheet.ChartObjects
If cht.Chart.HasTitle And cht.Chart.ChartTitle.Text = "X" Then
ActiveSheet.ChartObjects.Left = Cells(1, 14).Left
ActiveSheet.ChartObjects.Top = Cells(1, 14).Top
ActiveSheet.ChartObjects.Height = Range("N1:N22").Height
ActiveSheet.ChartObjects.Width = Range("N1:Y1").Width
End If
Next cht
Bookmarks