Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Find variable with the highest value
Hi, I have 5 variables containing integers. How can I use vba to
identify the variable with the highest value? Thanks Matt |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Find variable with the highest value
There is no magic here...
dim lngMax as long lngMax = Int1 if Int2 lngMax then lngMax = Int2 if Int3 lngMax then lngMax = Int3 if Int4 lngMax then lngMax = Int4 if Int5 lngMax then lngMax = Int5 -- HTH... Jim Thomlinson "MJKelly" wrote: Hi, I have 5 variables containing integers. How can I use vba to identify the variable with the highest value? Thanks Matt |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Find variable with the highest value
You can do call out to the worksheet's MAX function...
MaxVal = WorksheetFunction.Max(Int1, Int2, Int3, Int4, Int5) -- Rick (MVP - Excel) "MJKelly" wrote in message ... Hi, I have 5 variables containing integers. How can I use vba to identify the variable with the highest value? Thanks Matt |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Find variable with the highest value
Option Explicit
Dim maxint As String Dim maxval As Long Sub CheckMax() Dim int1 As Long Dim int2 As Long Dim int3 As Long Dim int4 As Long Dim int5 As Long int1 = Rnd() * 100 int2 = Rnd() * 100 int3 = Rnd() * 100 int4 = Rnd() * 100 int5 = Rnd() * 100 getmax 1, int1 getmax 2, int2 getmax 3, int2 getmax 4, int4 getmax 5, int5 MsgBox "Integer " & maxint & " hax max value of " & maxval End Sub Sub getmax(ByRef text As String, ByRef intval As Long) If intval maxval Then maxval = intval maxint = text End If End Sub "MJKelly" wrote in message ... Hi, I have 5 variables containing integers. How can I use vba to identify the variable with the highest value? Thanks Matt |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How do I find the second highest value. | Excel Discussion (Misc queries) | |||
how do I find 2nd highest MAX in a row | Excel Discussion (Misc queries) | |||
need to find highest total | Excel Programming | |||
Find the highest value on the column | Excel Discussion (Misc queries) | |||
Displaying the Highest Value in a user-variable range of cells | Excel Programming |