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: 6,582
Default How can I calculate the minimum value of a VBA array?

You've declared your arrays with no specific data type, so they are by
default variants. Variants could contain strings, numbers, or errors, and
only an array of numbers can have a valid minimum. What types of values do
the arrays contain? You need to check each array element to be certain.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"DJMF" wrote in message
...
I have an array of numbers that I have calculated by multiplying the
contents
of two other VBA arrays. I need to calculate the minimum value of the
final
calculated array, and I can't get the worksheetfunction.min to work
(although
it works for arrays read directly into VBA from a worksheet). According
to
the error there is a type mismatch, but no matter what I do with
definitions,
I can't get it to work. Here is a cut-out section of the code with the
offending line at the bottom. Thanks

Dim a, b, c, Counta, Countb, MaxData, MinimumValue
Dim CombinedData, CombinedRelativeFrequency


Cells(9, 1).Select
Range(Selection, Selection.End(xlDown)).Select
Counta = Application.WorksheetFunction.Count(Selection)

Cells(9, 5).Select
Range(Selection, Selection.End(xlDown)).Select
Countb = Application.WorksheetFunction.Count(Selection)

Dim A3(1 To 1000, 1 To 2)
Dim A4(1 To 1000, 1 To 2)
Dim A5(1 To 1000000, 1 To 2)
Dim A6(1 To 1000, 1 To 2)
Dim A7(1 To 1000000, 1 To 2)
Dim A8(1 To 1000000)
Dim A9(1 To 1000000, 1 To 2)
Dim A10(1 To 1000000)

c = 0

For a = 1 To Counta

A3(a, 1) = Cells(8 + a, 1).Value
A3(a, 2) = Cells(8 + a, 2).Value

For b = 1 To Countb

A4(b, 1) = Cells(8 + b, 5).Value
A4(b, 2) = Cells(8 + b, 6).Value

c = c + 1

CombinedData = A3(a, 1) * A4(b, 1)
CombinedRelativeFrequency = A3(a, 2) * A4(b, 2)

If CombinedRelativeFrequency 0 Then
A5(c, 1) = CombinedData
A8(c) = CombinedData
A5(c, 2) = CombinedRelativeFrequency
Else
c = c - 1
End If

Next b

Next a

For d = 1 To Countd
MinimumValue = Application.WorksheetFunction.Min(A8())





 
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
calculate cell value with a minimum to be displayed Dearoledad Excel Discussion (Misc queries) 3 October 17th 09 01:10 AM
need help with if statement that calculate minimum figure KateZed Excel Worksheet Functions 2 November 17th 08 06:41 PM
How to calculate non-zero minimum value? yhoy Excel Discussion (Misc queries) 5 February 24th 08 01:41 AM
How to calculate minimum distance between three coordinate with ex Jonathan[_2_] Excel Discussion (Misc queries) 2 November 29th 07 03:12 AM
Calculate Minimum numbers Pete Excel Worksheet Functions 2 May 12th 05 04:31 PM


All times are GMT +1. The time now is 02:59 PM.

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"