I have another pretty perplexing problem that one of you might be able to solve. So basically I have this code to write a line graph using Excel VBA. It’s made so it can be dynamic and can change if more values are added. But it’s reading the first value as 0 and the last value as 0 even though they are not 0. Here is the code I’m using to put the graph on the page.
Sub createchart4()
lastA = Range("A1").End(xlDown).Row
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=Range("Main!$A$1:$A$" & lastA)
ActiveChart.ChartTitle.Select
ActiveChart.SeriesCollection(1).Name = "=Main!$A$1"
ActiveChart.SeriesCollection(1).Values = "=Main!$A$3:$A$" & lastA
End Sub
It’s saying that A3’s value is 0 when it’s actually 1534 and it’s also reading A10 and A11 as 0 also when they’re different as well.
If you can figure this out, I would be amazed 😀
The only scenario when a Chart ignores a number is when the number is stored as text. See Snapshot
How to know if the number is stored as text and how do we rectify it?
If you are using Excel 2003 then go to menu
Tools | Options. Under theError CheckingTab, ensure that the checkboxNumber Stored as textis checked.In Excel 2007/2010, click on
Excel Optionswhich can be accessed from theOffice Iconin Excel 2007 orOptionsin theFileTab in Excel 2010.Go to the
Formulastab and ensure thatNumbers formatted as text or preceded by an apostropheis checked.If the above checkbox is checked then you will notice a small Green Triangle as shown in the snapshot above. Select the entire range starting from the 1st cell which has the Green Triangle. Click on the
Exclamation mark. Click onConvert to numberand you are done.