Replace zero array values with #N/A for chart

NdNoviceHlp

Well-known Member
Joined
Nov 9, 2002
Messages
3,623
The objective is to not chart zero values in a chart with an array source. I would like to replace the array zero values with #N/A which should then be ignored by the chart but... I can't seem to stumble across the correct syntax to replace the array zero values to #N/A in a format that the chart will accept. I've trialed the code(s) below without success. Any assistance will be appreciated. Dave
Code:
'CRVArr contains an array of arrays with chart source data
For Cnt = LBound(CRVArr(Index)) To UBound(CRVArr(Index))
'CRVArr(Index)(Cnt) = Replace$(CRVArr(Index)(Cnt), "0", "#N/A")
'CPFTArr(Index)(Cnt) = Replace$(CPFTArr(Index)(Cnt), "0", "#N/A")
If CRVArr(Index)(Cnt) <> 0 Then
CRVArr(Index)(Cnt) = CRVArr(Index)(Cnt)
CPFTArr(Index)(Cnt) = CPFTArr(Index)(Cnt)
Else
CRVArr(Index)(Cnt) = "#N/A" '"NA()" 'CVErr(xlErrNA)
CPFTArr(Index)(Cnt) = "#N/A" '"NA()" 'CVErr(xlErrNA)
End If
Next Cnt
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Try cverr(xlerrna)
 
Upvote 0
Thanks RoryA. I was a bit cryptic "I've trialed these code below"...
Code:
CRVArr(Index)(Cnt) = "#N/A" '"NA()" 'CVErr(xlErrNA)
I think that produces a number and the chart series wants the actual #N/A string as a value if that's possible? Dave
 
Upvote 0
After some trial and error it seems like you can't insert the #N/A in an array in any useful charting way. To remove the zeroes from the array, it just requires creating a new array without the zeroes and then passing that array to the chart. Solved. Dave
Code:
Dim TArr1() As Variant, Tarr2() As Variant, Cnt As Integer, Cnt2 As Integer

For Cnt = 1 To SRsCnt
For Cnt2 = LBound(CRVArr(Cnt - 1)) To UBound(CRVArr(Cnt - 1))
If CRVArr(Cnt - 1)(Cnt2) <> 0 Then
ReDim Preserve TArr1(Cnt2 + 1)
ReDim Preserve Tarr2(Cnt2 + 1)
TArr1(Cnt2) = CRVArr(Cnt - 1)(Cnt2)
Tarr2(Cnt2) = CPFTArr(Cnt - 1)(Cnt2)
End If
Next Cnt2

With ObjWorksheetCRV.ChartObjects("CRVChart").Chart
.SeriesCollection.NewSeries
.SeriesCollection(Cnt).XValues = TArr1  'CRVArr(Cnt - 1)
.SeriesCollection(Cnt).Values = Tarr2  'CPFTArr(Cnt - 1)
'etc
End With
Next Cnt
 
Upvote 0
Solution

Forum statistics

Threads
1,215,097
Messages
6,123,076
Members
449,094
Latest member
mystic19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top