+ Reply to Thread
Results 1 to 4 of 4

How to have Cell values (strings) on an Chart X-Axis

  1. #1
    Registered User
    Join Date
    01-18-2018
    Location
    London
    MS-Off Ver
    2010
    Posts
    2

    How to have Cell values (strings) on an Chart X-Axis

    have created a simple embedded chart but after trying for hours I see myself unable to set the X-Axis values to a set of cell values (I just get numbers starting from 1).

    Dim cht1 As ChartObject
    Dim rng1 As Range
    Worksheets(2).Activate



    Set rng1 = ActiveSheet.Range("D2:E13")
    Range("D15").Select
    Set cht1 = ActiveSheet.ChartObjects.Add( _
    Left:=ActiveCell.Left, _
    Width:=274, _
    Top:=ActiveCell.Top, _
    Height:=230)
    cht1.Chart.SetSourceData Source:=rng1
    cht1.Chart.ChartType = xlXYScatterLines
    cht1.Chart.Legend.Delete



    So, this piece of code above is displaying a chart where the Y values are taken from the E column (numbers) and the X values should be taken from the D column (text), but instead is just showing numbers starting from 1.

    Any ideas on how to do that.

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: How to have Cell values (strings) on an Chart X-Axis

    Hi,

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
    Don
    Please remember to mark your thread 'Solved' when appropriate.

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

    Re: How to have Cell values (strings) on an Chart X-Axis

    This forum can be strict about rules -- like embedding code with code tags. FAQ link includes instructions for adding code tags. You will want to comply to avoid having your topic locked.

    If your X values in column D are text and not numbers, then why are you using a scatter chart that expects numbers in the X values?
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  4. #4
    Registered User
    Join Date
    01-18-2018
    Location
    London
    MS-Off Ver
    2010
    Posts
    2

    Re: How to have Cell values (strings) on an Chart X-Axis

    Thanks MrShorty. You just solved my problem. I'm new with VBA and just picked the first option with lines that I saw.
    I'll take into account advise about embedding code with code tags.

+ 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. Replies: 9
    Last Post: 09-22-2015, 02:43 AM
  2. [SOLVED] Chart Axis Label according to 2 cell values
    By CobraLAD in forum Excel Charting & Pivots
    Replies: 7
    Last Post: 11-26-2014, 10:15 AM
  3. [SOLVED] set values as x axis and y axis in excel chart and name points
    By christopherL in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-27-2014, 10:19 AM
  4. Bubbel Chart with non-numerical values for both X axis and Y axis
    By air15567 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 07-29-2014, 11:25 AM
  5. Replies: 1
    Last Post: 03-01-2014, 07:10 AM
  6. [SOLVED] how to put x axis values in the chart instead of x axis labels
    By Sinclair in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 06-21-2005, 06:05 AM
  7. [SOLVED] How do I change X-Axis values in a chart with 2 Y-Axis?
    By ESGLCC in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 05-04-2005, 10:06 AM

Tags for this Thread

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