Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 90266

Setting a charts data range in VBA

$
0
0

I am helping to revamp the Excel sheets the management team uses for business analysis. I am making a dashboard page that displays the data in an easy to digest manner. They add data to the data pages, hit a button, and it refreshes the values.

My issue is getting the chart to automatically update the ranges in it. The chart has two data series, bids submitted and bids won, plotted against weeks. As the weeks in the year go, the chart will have more data in it.

My code looks like this

Sub Dashboard_Tool()

Dim Sh1 As Worksheet
Dim sh2 As Worksheet
Dim Myvalue As String
Dim lastcell As Range
Dim B As Byte
Dim P As Byte

'this is to get the bid info
Set Sh1 = Worksheets("New Dashboard")
Set sh2 = Worksheets("MI Dashboard")

For B = 1 To 12
    Myvalue = sh2.Cells(9, B + 9)
    Sh1.Cells(26, 3).Value = Myvalue
    Sh1.Cells(26, 2).Value = "This Month ("& sh2.Cells(8, B + 9) & ")"
    If sh2.Cells(9, B + 10).Value = "" Then Exit For
Next B

Set lastcell = sh2.Cells(9, B + 9)
Debug.Print lastcell.Value
ActiveSheet.ChartObjects("Bid Chart").Activate
Application.CutCopyMode = False
ActiveChart.FullSeriesCollection(1).Values = "='MI Dashboard'!$K$9:"& Cells(lastcell.Row, lastcell.Column)

It is the last lime I have quoted that is the issue. No matter which way I write the expression I get the same error

Run-Time error '1004':
Application defined or object defined error

I tried rewriting this line of code in a number of ways. The variable for this is the column. The row is always number 9.


Viewing all articles
Browse latest Browse all 90266

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>