LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default VBA code to erase an array element returning Error 2042 ???

Probably easier to make another array for your min/max functions

Untested -

' other declarations
Dim nCnt As Long
Dim arrVals() As Double

For iSrs = 1 To nSrs
'these are chart series

yVals = ActiveChart.SeriesCollection(iSrs).Values
nVals = ActiveChart.SeriesCollection(iSrs).Points.Count
nVals = UBound(yVals)
nCnt = 0
ReDim arrVals(1 To nVals)
'test every single point in the serie
For iVals = 1 To UBound(yVals)
If Not IsError(yVals(iVals)) Then
nCnt = nCnt + 1
arrVals(nCnt) = yVals(iVals)
End If
Next
If nCnt < nVals Then
ReDim Preserve arrVals(1 To nCnt)
End If

Ymax(iSrs) = WorksheetFunction.Max(arrVals)
Ymin(iSrs) = WorksheetFunction.Min(arrVals)
Next

Although Worksheet functions are extremly fast in cells they are not so fast
when called in VBA. I suspect it would be quicker to get your min/max values
directly in the loop, which would also avoid the need to make the second
array.

Regards,
Peter T

"Patachoup" wrote in message
...
hello,

below is my code, I need to return Min and Max Values, but it doesn't work
if any value in the array returns error2042:

Thx

-----------------------
For iSrs = 1 To nSrs
'these are chart series
Yvals = ActiveChart.SeriesCollection(iSrs).Values
nVals = ActiveChart.SeriesCollection(iSrs).Points.Count

'test every single point in the serie
For iVals = 1 To nVals
If IsError(Yvals(iVals)) Then
Yvals.Points(iVals).Delete 'HERE is the line

I
need to change!
End If
Next

Ymax(iSrs) = WorksheetFunction.max(Yvals)
Ymin(iSrs) = WorksheetFunction.min(Yvals)
Next
-----------------------




"Ben McBen" wrote:

I think we need some more background - is it a 1 or 2 dim array, do you
merely wnt to blank out the entry or actually delete it.

If its 1 dimensional, then the "Filter" function should be useful. If

its
2d I think you will have to resort to more VBA.

Please also see:

http://www.ozgrid.com/forum/showthread.php?t=30439

"Patachoup" wrote:

Hello,

How to easily erase an single array element returning "Error 2042"

using VBA
code ?

Thx in advance





 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
vlookup error 2042 jer Excel Programming 0 November 27th 06 02:31 PM
Array problem: Key words-Variant Array, single-element, type mismatch error davidm Excel Programming 6 November 9th 05 05:54 AM
Array problem: Key words-Variant Array, single-element, type mismatch error davidm Excel Programming 1 November 8th 05 04:21 AM
Excel xlodbc error 2042 with SQLRetrieve ALK[_2_] Excel Programming 0 July 28th 05 03:05 PM
Error 2042 Barbara[_3_] Excel Programming 1 September 8th 03 08:16 PM


All times are GMT +1. The time now is 10:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"