Results 1 to 6 of 6

Thread: [RESOLVED] Plot graphs in excel

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2008
    Posts
    44

    Resolved [RESOLVED] Plot graphs in excel

    Hi guys,

    I have two columns of data (columns A and B) and I want to plot a graph using these data. I know that by default Excel will put data inthe first column (A) on the X-axis and data in the second column (B) on the Y-axis. Is there a way to put the second column on the X-axis without switching the columns?

    Thanks

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Plot graphs in excel

    I'll give you a hint

    Record a macro and follow the steps of creating a graph. When you are in the Step 2 of 4 Chart wizard, select the "Series" tab and make the relevant changes. when you are done i.e making the chart, stop the macro. You can amend the code later to suit your needs.

    if you still get stuck...yell

    We'll take it from there
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2008
    Posts
    44

    Re: Plot graphs in excel

    Hi Koolsid,

    Thanks for the hint. Actually I know how to do that. Here's my problem:

    ActiveChart.SeriesCollection(1).XValues = ActiveSheet.Range(q)
    ActiveChart.SeriesCollection(1).Values = ActiveSheet.Range(p)

    First of all I don't know what the name of Sheet1 is going to be so I use Activesheet. Secondly, I have the following codes:

    retVal = Create_Chart(Range1, Range2, Range3, TabName, "y vs. x", "y", "x")

    Function Create_Chart(r As String, p As String, q As String, T As String, cT As String, xat As String, yat As String)
    Range(xRange, yRange).Select
    Range1 = Selection.Address
    Range2 = yRange.Address
    Range3 = xRange.Address

    I get the message "Unable to set the Xvalues property of the Series Class"

  4. #4

    Thread Starter
    Member
    Join Date
    Mar 2008
    Posts
    44

    Re: Plot graphs in excel

    Actually "Object doesn't support this property of method" is the message I get

  5. #5
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Plot graphs in excel

    I recorded a macro and made changes... please make changes to suit your requirements... I have commented the code so that it is easy to understand...

    vb Code:
    1. Sub Macro4()
    2.     'Select the range where the data is
    3.     Range("B9:C13").Select
    4.     'Add Chart
    5.     Charts.Add
    6.     'I am plotting a line chart. Change this to the charttype that you want
    7.     ActiveChart.ChartType = xlLineMarkers
    8.    
    9.     'Set Sourece Data
    10.     ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("B9:C13"), PlotBy _
    11.         :=xlColumns
    12.    
    13.     'Assign Values
    14.     ActiveChart.SeriesCollection(1).XValues = "=Sheet1!R9C3:R13C3"
    15.     ActiveChart.SeriesCollection(1).Values = "=Sheet1!R9C2:R13C2"
    16.    
    17.     'Assign Series Names
    18.     ActiveChart.SeriesCollection(1).Name = "=Sheet1!R8C2"
    19.    
    20.     'Location where you want to plot the chart
    21.     'I am placing it in say sheet1
    22.     ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
    23.    
    24.     'Give title and do extra stuff...
    25.     With ActiveChart
    26.         .HasTitle = True
    27.         .ChartTitle.Characters.Text = "Blah Blah"
    28.         .Axes(xlCategory, xlPrimary).HasTitle = False
    29.         .Axes(xlValue, xlPrimary).HasTitle = False
    30.     End With
    31. End Sub
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  6. #6

    Thread Starter
    Member
    Join Date
    Mar 2008
    Posts
    44

    Re: Plot graphs in excel

    Koolsid, thanks for your help. I found a way around it so I'm going to mark it as Resolved.

Posting Permissions

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



Click Here to Expand Forum to Full Width