PDA

View Full Version : [HELP] Charts.Add and Range



gui_sa
05-22-2008, 01:32 PM
Hello there,
I?m having problemas with creating charts with no especific number of lines.
The program gets some data from the internet every time i run it, and i need to create a chart with it, but i can?t figure out how to put more data in the chart every time i run it...
If you understood what i wanted to say please help!
Thx


Sub charts()
Dim n As Integer
delete
n = Cells(65130, 1).End(xlUp).Row
With ActiveSheet.ChartObjects.Add _
(Left:=0, Width:=230, Top:=75, Height:=225)
.Chart.SetSourceData Source:=Sheets("Dados").Range(Cells(n, 1), Cells(n, 2)) 'How Can i fix the range?
.Chart.ChartType = xlXYScatterLines
End With

Bob Phillips
05-22-2008, 02:27 PM
Guessing a bit, sparse with detail on the need



Sub charts()
Dim n As Long
n = Sheets("Dados").Cells(65130, 1).End(xlUp).Row
With ActiveSheet.ChartObjects.Add _
(Left:=0, Width:=230, _
Top:=75, Height:=225)
.Chart.SetSourceData Source:=Sheets("Dados").Range("A1").Resize(n, 2)
.Chart.ChartType = xlXYScatterLines
End With
End Sub

gui_sa
05-22-2008, 02:42 PM
Thanks
That Helped A lot
But now i need to move those charts to another sheet
or just create them in this other sheet
so how do i do that?

i tried with this but the program just recognizes numbers and i don?t know how to put it for any char:

Sub movergrafico()
'
' movergrafico Macro
'

'
ActiveSheet.ChartObjects("Gr?fico 57").Activate
Selection.Cut
Sheets("graficos").Select
ActiveSheet.Paste
Sheets("portfolio").Select
ActiveSheet.ChartObjects("Gr?fico 58").Activate
Selection.Cut
Sheets("graficos").Select
Range("G4").Select
ActiveSheet.Paste
Sheets("portfolio").Select
ActiveSheet.ChartObjects("Gr?fico 59").Activate
Selection.Cut
Sheets("graficos").Select
Range("M8").Select
ActiveSheet.Paste
Sheets("portfolio").Select
ActiveSheet.ChartObjects("Gr?fico 60").Activate
Selection.Cut
Sheets("graficos").Select
Range("P3").Select
ActiveSheet.Paste
ActiveSheet.ChartObjects("Gr?fico 4").Activate
ActiveSheet.ChartObjects("Gr?fico 5").Activate
ActiveSheet.ChartObjects("Gr?fico 6").Activate
ActiveSheet.ChartObjects("Gr?fico 7").Activate
Range("H21").Select
End Sub

Thanks Again

gui_sa
05-22-2008, 03:01 PM
nevermind
already got it
thx for ur help