+ Reply to Thread
Results 1 to 5 of 5

VBA code for a chart

  1. #1
    Registered User
    Join Date
    10-18-2012
    Location
    United States
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    20

    VBA code for a chart

    I'm a beginner - I'm sure someone could fix the code in 10 seconds.

    I have graphs - 9 of them - in an excel spreadsheet. I have this VBA code that fixes the scale for these graphs. Only one problem - when I run the Macro, it changes the scale for all 9 graphs. I want to have separate macros for each chart. How can I do this?

    Here's my code:

    Sub ChangeAxisScales()
    Dim objCht As ChartObject
    For Each objCht In ActiveSheet.ChartObjects
    With objCht.Chart
    ' Value (Y) Axis
    With .Axes(xlValue)
    .MaximumScale = ActiveSheet.Range("$AC$3").Value
    .MinimumScale = ActiveSheet.Range("$AC$2").Value
    .MajorUnit = ActiveSheet.Range("$AC$4").Value
    End With
    End With
    Next objCht
    End Sub

    I'm pretty sure the problem is the "For Each" argument, but have no idea how to change that to impact the graphs individually.

    One graph needs to use max $AB$3, min $AB$2, and Major Unit $AB$4.
    Another graph needs $AC$3, $AC$2, and $AC$4, and etc. through column AJ.

    Thus, I want one Macro that changes my first graph scale to the AB cells, the second to the AC cells, ... , and the ninth one to AJ cells.

    Please help!

    Claude

  2. #2
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: VBA code for a chart

    One way you could do it is to replace
    Please Login or Register  to view this content.
    with
    Please Login or Register  to view this content.
    Let me know if you get stuck

  3. #3
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: VBA code for a chart

    Actually, sorry I didn't read the finer details of your post. This can be done a lot simpler! Try this:
    Please Login or Register  to view this content.
    The proviso with this method is that your charts must be named such that ActiveSheet.ChartObject(1) will use column AB, ActiveSheet.ChartObject(2) will use column AC and so on...so it may be that my previous post is actually the simpler of the 2 methods, otherwise you may have to delete some charts and start them again in the correct order, which would be extremely frustrating for 9 charts!

    Again, let me know how you go

  4. #4
    Registered User
    Join Date
    10-18-2012
    Location
    United States
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    20

    Re: VBA code for a chart

    As I was playing around with it, I found this worked!!

    Please Login or Register  to view this content.
    I'm going to go in and try the integer way now. It seems much tidier

    Thank you for your response!!

  5. #5
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: VBA code for a chart

    You're welcome! Glad I could help.

    Please don't forget to mark this thread as posted and click on the * next to my post to say thanks

    Have a great day

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. vba code to create chart and fix the axis of the chart
    By Sushil.thakur in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-21-2013, 06:14 AM
  2. VBA code for bar chart
    By laptop545 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-12-2010, 06:45 PM
  3. VBA code that analyzes an Excel chart, and then creates a Google Chart API
    By smilem in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-16-2008, 08:16 PM
  4. VBA code help for Chart
    By lok in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 01-03-2007, 02:11 AM
  5. Flow chart of code? Is there a way to produce a graphical flow chart?
    By Craigm in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-23-2005, 05:05 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