+ Reply to Thread
Results 1 to 3 of 3

Moving chart vertical grid lines in a horizintal direction with VBA

  1. #1
    Valued Forum Contributor luv2glyd's Avatar
    Join Date
    07-13-2008
    Location
    Seattle, WA, US
    MS-Off Ver
    Excel 2010
    Posts
    679

    Moving chart vertical grid lines in a horizintal direction with VBA

    I have a stock chart with 70 bars in it. If I insert vertical grid lines at a spacing of 7, excel positions them from left to right starting with the first one appearing after the 7th bar. Is it possible to move these lines horizontally so that the first line appears after bar 3 of the chart for example then continues to the right at a spacing of 7?

    I did not see an option for this in the grid-line edit box so wanted to see if VBA can do something. I know I can probably insert some blank spaces to the left of the chart to create this effect, but want to avoid doing this.

    Thanks
    You either quit or become really good at it. There are no other choices.

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,811

    Re: Moving chart vertical grid lines in a horizintal direction with VBA

    From what I can see, the position of vertical gridlines is tied to the position of tickmarks along the primary horizontal axis. If I understand what you are trying to do, acheiving this kind of "custom" position of grid lines will depend on exactly what type of horizontal axis your stock chart has: category/text or date. I don't see many options for a category/text axis -- you kind of take what you get. For a date axis, you can probably try different combinations of max, min, major unit, minor unit, values to see if you can get the desired effect. (Axis object help file with available properties: https://msdn.microsoft.com/en-us/lib.../ff834649.aspx ).

    I have not thought through all possible approaches using the basic tools built into Excel/VBA, but my first thought for the easiest way to do this is to do some kind of "stock" + line combination chart. The data series that is set as a line chart type can have vertical error bars to create the fake "gridlines". The "stock" chart (in quotes because the built in stock chart options don't seem to play nice when you want to make combination charts) would be created using other chart types (most stock chart types look like "stacked column" charts or "box and whiskers" type charts which are basically stacked column charts), which can easily be combined with the line chart series. This tutorial shows how to build a box and whiskers diagram + line combination chart: http://peltiertech.com/excel-box-and...ams-box-plots/ If I were trying to do what I think you are trying to do, that is how I would approach it.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Valued Forum Contributor luv2glyd's Avatar
    Join Date
    07-13-2008
    Location
    Seattle, WA, US
    MS-Off Ver
    Excel 2010
    Posts
    679

    Re: Moving chart vertical grid lines in a horizintal direction with VBA

    I think the error bars idea will work pretty well. I can add a line chart charting values of 0 and 1000 (1000 being where I want to make a grid line) to the stock chart, make it invisible and apply error bars to it pointed downwards. Since stock price is always above 0 and so is minimum price on the Y axis, the error bars displayed at 0 will be invisible and the ones at 1000 visible. Thanks for your help!

+ 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. [SOLVED] Reinsert horizintal axis in chart.
    By JO505 in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 07-25-2013, 08:02 PM
  2. Vertical lines on a chart?
    By ryanjb in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 01-25-2013, 05:38 AM
  3. Alternate Background Colors Between Vertical Grid Lines
    By whattheheck in forum Excel General
    Replies: 1
    Last Post: 04-09-2011, 12:14 AM
  4. Moving Vertical Lines
    By ajocius in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-24-2008, 09:50 PM
  5. Replies: 3
    Last Post: 03-03-2006, 12:20 AM
  6. [SOLVED] Why do vertical grid lines disappear in Excel?
    By rrgttn in forum Excel General
    Replies: 0
    Last Post: 01-17-2006, 08:30 PM
  7. [SOLVED] Grid Lines on an Area Chart
    By Phil Hageman in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 09-21-2005, 07:05 PM
  8. how can I fill labels in a chart, so that the grid lines don't in.
    By peterk in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 02-18-2005, 10: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