Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I'm working on some excel sheets, that contains 4 columns, each with 1000 values. I recently learnt how simple and quicker macros are and wanted to try that on my file to generate charts. In a code to generate a chart :
VB
Sub CreateChart()
   Range("C3").Select
   Selection.CurrentRegion.Select
   myrange = Selection.Address
   mysheetname = ActiveSheet.Name
   ActiveSheet.ChartObjects.Add(125.25, 60, 301.5, 155.25).Select
   Application.CutCopyMode = False
   ActiveChart.ChartWizard _
     Source:=Sheets(mysheetname).Range(myrange), _
     Gallery:=xlLine, Format:=4, PlotBy:=xlRows, _
     CategoryLabels:=1, SeriesLabels:=1, HasLegend:=1, _
     Title:="", CategoryTitle:="", _
     ValueTitle:="", ExtraTitle:=""
(This code is taken from the Microsoft support)
this code selects all the data from A1 to D5, but I just want to select one column. How can I do that ?
Posted
Updated 27-Jun-12 2:33am
v3

1 solution

The easiest thing to do is to record a macro doing what you want. So, you could start recording a macro, select one column, stop the macro and then look at the code.

Or, do this

VB
Range("A:A").Select
 
Share this answer
 
Comments
Sumal.V 27-Jun-12 8:30am    
if i record the macro,
ActiveChart.SeriesCollection(1).Name = "=Sheet1!$A$11"
ActiveChart.SeriesCollection(1).Values = "=Sheet1!$A$1:$A$11"
but again I do not want to specify the sheet name. I have updated my code.
ZurdoDev 27-Jun-12 8:40am    
So, do you still have a question? Or is it working for you?
Sumal.V 27-Jun-12 8:42am    
Yeah, In that above code, if I change the range to A1:A11, it still selects the entire area.
ZurdoDev 27-Jun-12 8:46am    
Can you be more specific? Which above code? And when it selects the entire area what do you mean by entire area?
Sumal.V 27-Jun-12 8:50am    
Sorry, I'm working based on an example from the link: http://support.microsoft.com/kb/213352

it contains cells C, D, E, F . when I say Range(C:C), the macro is applied to C, D, E, F as well not just C

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900