Consulting

Results 1 to 5 of 5

Thread: Vba data for chart

  1. #1

    Vba data for chart

    Hi

    Please service where i am making a mistake

    I need to select the data for the chart
    I do it this but it does not work



    Sub data_chart

    Dim chart as long

    chart = range("a5").end(xlToRight).offset(0, 1).select

    ActiveSheet.chartObject("chart 1").activate
    Active.Chart.ChartArea.select
    Activated.Chart.SetSourceData Source:=Range("a1" & ":" & "chart")

    End sub

    Thank you for your advice

  2. #2
    VBAX Expert
    Joined
    May 2016
    Posts
    604
    Location
    try this:
    With Worksheets("sheet1")
    lastcol = .Cells(1, .Columns.Count).End(xlToLeft).Column
    Row = 1
    End With
    Worksheets("Sheet1").ChartObjects("chart 1").Chart.SetSourceData Source:=Sheets("Sheet1").Range(Cells(Row, 1), Cells(Row, lastcol)), PlotBy:=xlRows
    Worksheets("Sheet1").ChartObjects("chart 1").Chart.ChartType = xlLine

  3. #3
    Unfortunately, this does not work. I need to find tle last full column and pit it in the graph data.

    The chart data will start with A1 and end up with F7, G7 or H7 and so on.
    The tabule will look:
    Attached Images Attached Images

  4. #4
    And graph will look:
    Attached Images Attached Images

  5. #5
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,875
    Sub data_chart()
    Dim chart As Long
    chart = Range("a5").End(xlToRight).Column
    ActiveSheet.ChartObjects("Chart 1").chart.SetSourceData Source:=Range(Cells(1, 1), Cells(7, chart))
    End Sub
    ?
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

Posting Permissions

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