Using VBA macro - how to just chart two selected columns

R

RLExcelUserTS

Using a VBA macro, I'm looking for the best way to Chart just the "X
axis" and the "Yaxis" from selected columns. Basically, just want to
chart one column vs another column located anywhere in the worksheet.

Tried three ways.

a) Hardcode cell address.
b) Range cell selection.
c) Cell address obtained from range.

I believe there is a better way, but have not found it yet.

Refer to code snipet

*******
Range(XAXISTOPCELLGRAPH1, XAXISTOPCELLGRAPH1).Select

Range(ActiveCell, ActiveCell.End(xlDown)).Select

Range(YAXISTOPCELLGRAPH1, YAXISTOPCELLGRAPH1).Select

Range(ActiveCell, ActiveCell.End(xlDown)).Select

' Add Chart

Charts.Add

ActiveChart.ChartType = xlXYScatterLinesNoMarkers

' ActiveChart.SetSourceData Source:=Sheets(DATASHEETNAME). _

' Range("A1:A602,B1:B602")

' ActiveChart.SetSourceData Source:=Sheets(DATASHEETNAME). _

' Range(UXCell, LYCell), PlotBy:=xlColumns

ActiveChart.SetSourceData Source:=Sheets(DATASHEETNAME). _

Range(XColRange & "," & YColRange)

ActiveChart.Location Where:=xlLocationAsObject, Name:= _

GRAPHSHEETNAME
*******


Thanks for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top