Results 1 to 5 of 5

Chart Objects Cont'd

Threaded View

  1. #1
    Forum Contributor
    Join Date
    02-26-2012
    Location
    Ottawa, ON
    MS-Off Ver
    Excel 2007
    Posts
    129

    Chart Objects Cont'd

    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
    Last edited by NatalieEC; 09-25-2014 at 09:33 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Chart Objects
    By NatalieEC in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-24-2014, 02:58 PM
  2. How to Name Chart Objects
    By DCSwearingen in forum Excel General
    Replies: 2
    Last Post: 07-30-2006, 05:27 AM
  3. [SOLVED] Chart Objects Error
    By Bill in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-14-2005, 01:05 AM
  4. [SOLVED] Chart Objects
    By Bill in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-18-2005, 09:05 AM
  5. Protecting chart objects
    By julia.stone@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-18-2005, 09:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1