Consulting

Results 1 to 6 of 6

Thread: macro for charting

  1. #1
    VBAX Contributor
    Joined
    Apr 2012
    Posts
    107
    Location

    macro for charting

    What's with this code
    ActiveChart.SetSourceData Source:=Range("A2:C2", "C" & LR).Select
    [vba]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
    [/vba]

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    This does stuff for me.

    [vba]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
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Contributor
    Joined
    Apr 2012
    Posts
    107
    Location
    run your macro but not working

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    As I said, it did stuff for me, not working doesn't tell me much (read nothing!).
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Contributor
    Joined
    Apr 2012
    Posts
    107
    Location

    macro for charting

    I re-write the macro but there is error: cht.Chart.SetSourceData Source:=Range("A2:C2", "C" & LR)
    [VBA]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 [/VBA]
    Attached Files Attached Files

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    So it was your changes that didn't work, not my code!

    [vba]
    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[/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •