|
-
Nov 2nd, 2008, 08:51 PM
#1
Thread Starter
Member
[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
-
Nov 3rd, 2008, 06:56 AM
#2
-
Nov 3rd, 2008, 01:00 PM
#3
Thread Starter
Member
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"
-
Nov 3rd, 2008, 01:04 PM
#4
Thread Starter
Member
Re: Plot graphs in excel
Actually "Object doesn't support this property of method" is the message I get
-
Nov 4th, 2008, 01:24 PM
#5
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:
Sub Macro4()
'Select the range where the data is
Range("B9:C13").Select
'Add Chart
Charts.Add
'I am plotting a line chart. Change this to the charttype that you want
ActiveChart.ChartType = xlLineMarkers
'Set Sourece Data
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("B9:C13"), PlotBy _
:=xlColumns
'Assign Values
ActiveChart.SeriesCollection(1).XValues = "=Sheet1!R9C3:R13C3"
ActiveChart.SeriesCollection(1).Values = "=Sheet1!R9C2:R13C2"
'Assign Series Names
ActiveChart.SeriesCollection(1).Name = "=Sheet1!R8C2"
'Location where you want to plot the chart
'I am placing it in say sheet1
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
'Give title and do extra stuff...
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Blah Blah"
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With
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
-
Nov 16th, 2008, 04:03 PM
#6
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|