PDA

View Full Version : macro for charting



asdzxc
04-25-2012, 11:23 PM
What's with this code
ActiveChart.SetSourceData Source:=Range("A2:C2", "C" & LR).Select
Range("C8").Select
ActiveCell.FormulaR1C1 = "=(R[-3]C2)*2-R[-6]C2"
Range("C8").Select
Selection.AutoFill Destination:=Range("C8:C50"), Type:=xlFillDefault
Range("C8:C50").Select
Range("A1:C14").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlLineMarkers
With Range("A" & Rows.Count).End(xlUp)
.AutoFill .Resize(4)

Dim LR As Long
LR = Range("B2").End(xlDown).Offset(3, 0).Row
ActiveChart.SetSourceData Source:=Range("A2:C2", "C" & LR).Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlLineMarkers

End With
End Sub

Bob Phillips
04-26-2012, 01:28 AM
This does stuff for me.

Dim cht As Object
Dim cht1 As Object

Range("C8:C50").FormulaR1C1 = "=(R[-3]C2)*2-R[-6]C2"
Set cht = ActiveSheet.Shapes.AddChart
cht.Chart.ChartType = xlLineMarkers
With Range("A" & Rows.Count).End(xlUp)
.AutoFill .Resize(4)

Dim LR As Long
LR = Range("B2").End(xlDown).Row
cht.Chart.SetSourceData Source:=Range("A2:C2", "C" & LR)
Set cht1 = ActiveSheet.Shapes.AddChart
cht1.Chart.ChartType = xlLineMarkers
End With

asdzxc
04-26-2012, 01:46 AM
run your macro but not working

Bob Phillips
04-26-2012, 01:50 AM
As I said, it did stuff for me, not working doesn't tell me much (read nothing!).

asdzxc
04-26-2012, 01:58 AM
I re-write the macro but there is error: cht.Chart.SetSourceData Source:=Range("A2:C2", "C" & LR)
Dim cht As Object
Dim cht1 As Object
Range("C8").Select
ActiveCell.FormulaR1C1 = "=(R[-3]C2)*2-R[-6]C2"
Range("C8").Select
Selection.AutoFill Destination:=Range("C8:C50"), Type:=xlFillDefault
Range("C8:C50").Select


With Range("A" & Rows.Count).End(xlUp)
.AutoFill .Resize(4)

Dim LR As Long
LR = Range("B2").End(xlDown).Row
cht.Chart.SetSourceData Source:=Range("A2:C2", "C" & LR)
Set cht1 = ActiveSheet.Shapes.AddChart
cht1.Chart.ChartType = xlLineMarkers

End With
End Sub

Bob Phillips
04-26-2012, 02:23 AM
So it was your changes that didn't work, not my code!


Sub CreateChart()
Dim cht As Object
Dim LR As Long

Range("C8:C50").FormulaR1C1 = "=(R[-3]C2)*2-R[-6]C2"

With Range("A" & Rows.Count).End(xlUp)
.AutoFill .Resize(4)

LR = Range("B2").End(xlDown).Row
Set cht = ActiveSheet.Shapes.AddChart
cht.Chart.ChartType = xlLineMarkers
cht.Chart.SetSourceData Source:=Range("A2", "C" & LR)
End With
End Sub