Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 115
Default One line query on for loop assignment

I have a line
ActiveChart.SeriesCollection(i).Name = Sheets("Sheet1").Cells(j, 2)
for assigning the legend name in a scatter chart which works
correctly.

I would like to assign .values from cells(j,1) to cells(k,1).. What is
the correct syntax to do it?
I get an error when I have a line like this.

ActiveChart.SeriesCollection(i).Values = Sheets("Sheet1").Cells(j,
1):cells(k,1)

Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default One line query on for loop assignment

Encase it in a Range, as follows:
Sheets("Sheet1").Range(Cells(j,1),Cells(k,1))

" wrote:

I have a line
ActiveChart.SeriesCollection(i).Name = Sheets("Sheet1").Cells(j, 2)
for assigning the legend name in a scatter chart which works
correctly.

I would like to assign .values from cells(j,1) to cells(k,1).. What is
the correct syntax to do it?
I get an error when I have a line like this.

ActiveChart.SeriesCollection(i).Values = Sheets("Sheet1").Cells(j,
1):cells(k,1)

Thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 115
Default One line query on for loop assignment

On Oct 21, 12:49 am, Cringing Dragon
wrote:
Encase it in a Range, as follows:
Sheets("Sheet1").Range(Cells(j,1),Cells(k,1))



" wrote:
I have a line
ActiveChart.SeriesCollection(i).Name = Sheets("Sheet1").Cells(j, 2)
for assigning the legend name in a scatter chart which works
correctly.


I would like to assign .values from cells(j,1) to cells(k,1).. What is
the correct syntax to do it?
I get an error when I have a line like this.


ActiveChart.SeriesCollection(i).Values = Sheets("Sheet1").Cells(j,
1):cells(k,1)


Thanks- Hide quoted text -


- Show quoted text -


Thanks. But, I get an error like this

Method 'cells' of object '_Global' failed.

Please help me fix the error.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default One line query on for loop assignment

How did you apply it? I didn't show the whole line, just the bit of it that I
was suggesting you change. The whole line needs to be:
ActiveChart.SeriesCollection(i).Values =
Sheets("Sheet1").Range(Cells(j,1),Cells(k,1))

In this post, that will wrap around onto 2 lines. You need to put it all on
one line.

If that's what you did already, or if you still get the error, can you
please post the block of lines around that one (ie the line before, that
line, and the line after)? Copy and paste them straight from your code, so I
can see exactly what you have.

" wrote:

On Oct 21, 12:49 am, Cringing Dragon
wrote:
Encase it in a Range, as follows:
Sheets("Sheet1").Range(Cells(j,1),Cells(k,1))



" wrote:
I have a line
ActiveChart.SeriesCollection(i).Name = Sheets("Sheet1").Cells(j, 2)
for assigning the legend name in a scatter chart which works
correctly.


I would like to assign .values from cells(j,1) to cells(k,1).. What is
the correct syntax to do it?
I get an error when I have a line like this.


ActiveChart.SeriesCollection(i).Values = Sheets("Sheet1").Cells(j,
1):cells(k,1)


Thanks- Hide quoted text -


- Show quoted text -


Thanks. But, I get an error like this

Method 'cells' of object '_Global' failed.

Please help me fix the error.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 115
Default One line query on for loop assignment

On Oct 21, 1:18 am, Cringing Dragon
wrote:
How did you apply it? I didn't show the whole line, just the bit of it that I
was suggesting you change. The whole line needs to be:
ActiveChart.SeriesCollection(i).Values =
Sheets("Sheet1").Range(Cells(j,1),Cells(k,1))

In this post, that will wrap around onto 2 lines. You need to put it all on
one line.

If that's what you did already, or if you still get the error, can you
please post the block of lines around that one (ie the line before, that
line, and the line after)? Copy and paste them straight from your code, so I
can see exactly what you have.



" wrote:
On Oct 21, 12:49 am, Cringing Dragon
wrote:
Encase it in a Range, as follows:
Sheets("Sheet1").Range(Cells(j,1),Cells(k,1))


" wrote:
I have a line
ActiveChart.SeriesCollection(i).Name = Sheets("Sheet1").Cells(j, 2)
for assigning the legend name in a scatter chart which works
correctly.


I would like to assign .values from cells(j,1) to cells(k,1).. What is
the correct syntax to do it?
I get an error when I have a line like this.


ActiveChart.SeriesCollection(i).Values = Sheets("Sheet1").Cells(j,
1):cells(k,1)


Thanks- Hide quoted text -


- Show quoted text -


Thanks. But, I get an error like this


Method 'cells' of object '_Global' failed.


Please help me fix the error.- Hide quoted text -


- Show quoted text -


Hi.. ya I did as u said i.e. had it in a single line. The code is
given below

Charts.Add
ActiveChart.ChartType = xlXYScatter

For i = 1 To 10
j = ((i - 1) * 524) + 46
k = j + 523

ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(i).XValues = "='Sheet1'!R46C3:R569C3"

ActiveChart.SeriesCollection(i).Values =
Sheets("Sheet1").Range(Cells(j, 1), Cells(k, 1)) ' ****Error here
ActiveChart.SeriesCollection(i).Name = Sheets("Sheet1").Cells(j, 2)

Next

End Sub

I hope to see ur reply when I wake up tomorrow morning. Thank you very
much.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default One line query on for loop assignment

Sorry, yes I forgot to put the sheet reference in front of the cells.
Sheets("Sheet1").Range(Sheets("Sheet1").Cells(j,1) ,Sheets("Sheet1").Cells(k,1))

Give that a shot.

--
If a post answers your question, please mark it as the answer.


" wrote:

On Oct 21, 1:18 am, Cringing Dragon
wrote:
How did you apply it? I didn't show the whole line, just the bit of it that I
was suggesting you change. The whole line needs to be:
ActiveChart.SeriesCollection(i).Values =
Sheets("Sheet1").Range(Cells(j,1),Cells(k,1))

In this post, that will wrap around onto 2 lines. You need to put it all on
one line.

If that's what you did already, or if you still get the error, can you
please post the block of lines around that one (ie the line before, that
line, and the line after)? Copy and paste them straight from your code, so I
can see exactly what you have.



" wrote:
On Oct 21, 12:49 am, Cringing Dragon
wrote:
Encase it in a Range, as follows:
Sheets("Sheet1").Range(Cells(j,1),Cells(k,1))


" wrote:
I have a line
ActiveChart.SeriesCollection(i).Name = Sheets("Sheet1").Cells(j, 2)
for assigning the legend name in a scatter chart which works
correctly.


I would like to assign .values from cells(j,1) to cells(k,1).. What is
the correct syntax to do it?
I get an error when I have a line like this.


ActiveChart.SeriesCollection(i).Values = Sheets("Sheet1").Cells(j,
1):cells(k,1)


Thanks- Hide quoted text -


- Show quoted text -


Thanks. But, I get an error like this


Method 'cells' of object '_Global' failed.


Please help me fix the error.- Hide quoted text -


- Show quoted text -


Hi.. ya I did as u said i.e. had it in a single line. The code is
given below

Charts.Add
ActiveChart.ChartType = xlXYScatter

For i = 1 To 10
j = ((i - 1) * 524) + 46
k = j + 523

ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(i).XValues = "='Sheet1'!R46C3:R569C3"

ActiveChart.SeriesCollection(i).Values =
Sheets("Sheet1").Range(Cells(j, 1), Cells(k, 1)) ' ****Error here
ActiveChart.SeriesCollection(i).Name = Sheets("Sheet1").Cells(j, 2)

Next

End Sub

I hope to see ur reply when I wake up tomorrow morning. Thank you very
much.


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default One line query on for loop assignment

If sheet1 isn't the active sheet or the code is in a sheet module other than
sheet1, then qualify all references like this:

With Sheets("Sheet1")
ActiveChart.SeriesCollection(i).Values = _
.Range(.Cells(j,1),.Cells(k,1))
End With

--
Regards,
Tom Ogilvy


" wrote:

On Oct 21, 1:18 am, Cringing Dragon
wrote:
How did you apply it? I didn't show the whole line, just the bit of it that I
was suggesting you change. The whole line needs to be:
ActiveChart.SeriesCollection(i).Values =
Sheets("Sheet1").Range(Cells(j,1),Cells(k,1))

In this post, that will wrap around onto 2 lines. You need to put it all on
one line.

If that's what you did already, or if you still get the error, can you
please post the block of lines around that one (ie the line before, that
line, and the line after)? Copy and paste them straight from your code, so I
can see exactly what you have.



" wrote:
On Oct 21, 12:49 am, Cringing Dragon
wrote:
Encase it in a Range, as follows:
Sheets("Sheet1").Range(Cells(j,1),Cells(k,1))


" wrote:
I have a line
ActiveChart.SeriesCollection(i).Name = Sheets("Sheet1").Cells(j, 2)
for assigning the legend name in a scatter chart which works
correctly.


I would like to assign .values from cells(j,1) to cells(k,1).. What is
the correct syntax to do it?
I get an error when I have a line like this.


ActiveChart.SeriesCollection(i).Values = Sheets("Sheet1").Cells(j,
1):cells(k,1)


Thanks- Hide quoted text -


- Show quoted text -


Thanks. But, I get an error like this


Method 'cells' of object '_Global' failed.


Please help me fix the error.- Hide quoted text -


- Show quoted text -


Hi.. ya I did as u said i.e. had it in a single line. The code is
given below

Charts.Add
ActiveChart.ChartType = xlXYScatter

For i = 1 To 10
j = ((i - 1) * 524) + 46
k = j + 523

ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(i).XValues = "='Sheet1'!R46C3:R569C3"

ActiveChart.SeriesCollection(i).Values =
Sheets("Sheet1").Range(Cells(j, 1), Cells(k, 1)) ' ****Error here
ActiveChart.SeriesCollection(i).Name = Sheets("Sheet1").Cells(j, 2)

Next

End Sub

I hope to see ur reply when I wake up tomorrow morning. Thank you very
much.


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 115
Default One line query on for loop assignment

On Oct 21, 5:12 am, Tom Ogilvy
wrote:
If sheet1 isn't the active sheet or the code is in a sheet module other than
sheet1, then qualify all references like this:

With Sheets("Sheet1")
ActiveChart.SeriesCollection(i).Values = _
.Range(.Cells(j,1),.Cells(k,1))
End With

--
Regards,
Tom Ogilvy



" wrote:
On Oct 21, 1:18 am, Cringing Dragon
wrote:
How did you apply it? I didn't show the whole line, just the bit of it that I
was suggesting you change. The whole line needs to be:
ActiveChart.SeriesCollection(i).Values =
Sheets("Sheet1").Range(Cells(j,1),Cells(k,1))


In this post, that will wrap around onto 2 lines. You need to put it all on
one line.


If that's what you did already, or if you still get the error, can you
please post the block of lines around that one (ie the line before, that
line, and the line after)? Copy and paste them straight from your code, so I
can see exactly what you have.


" wrote:
On Oct 21, 12:49 am, Cringing Dragon
wrote:
Encase it in a Range, as follows:
Sheets("Sheet1").Range(Cells(j,1),Cells(k,1))


" wrote:
I have a line
ActiveChart.SeriesCollection(i).Name = Sheets("Sheet1").Cells(j, 2)
for assigning the legend name in a scatter chart which works
correctly.


I would like to assign .values from cells(j,1) to cells(k,1).. What is
the correct syntax to do it?
I get an error when I have a line like this.


ActiveChart.SeriesCollection(i).Values = Sheets("Sheet1").Cells(j,
1):cells(k,1)


Thanks- Hide quoted text -


- Show quoted text -


Thanks. But, I get an error like this


Method 'cells' of object '_Global' failed.


Please help me fix the error.- Hide quoted text -


- Show quoted text -


Hi.. ya I did as u said i.e. had it in a single line. The code is
given below


Charts.Add
ActiveChart.ChartType = xlXYScatter


For i = 1 To 10
j = ((i - 1) * 524) + 46
k = j + 523


ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(i).XValues = "='Sheet1'!R46C3:R569C3"


ActiveChart.SeriesCollection(i).Values =
Sheets("Sheet1").Range(Cells(j, 1), Cells(k, 1)) ' ****Error here
ActiveChart.SeriesCollection(i).Name = Sheets("Sheet1").Cells(j, 2)


Next


End Sub


I hope to see ur reply when I wake up tomorrow morning. Thank you very
much.- Hide quoted text -


- Show quoted text -


Tom, your code works perfectly. Thanks a lot.. Can you please suggest
me a book that can train me with VBA (coding) for charts? Thanks..

Cringing Dragon, I used your code but I got an error saying "Subscript
out of range". I mark Tom's code as the best fit for this thread.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Line Chart Query Furn16 Charts and Charting in Excel 1 December 19th 09 02:36 AM
Do without loop when using query [email protected][_2_] Excel Programming 1 June 7th 07 05:09 PM
LOOP query Pedro AM Excel Discussion (Misc queries) 2 February 14th 07 05:32 AM
Code bombing on Loop While line JMay Excel Programming 3 December 26th 05 10:16 PM
Looping SQL query w/changing parameters in each loop not working Laurin[_3_] Excel Programming 7 December 9th 05 03:35 PM


All times are GMT +1. The time now is 07:26 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"