Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default 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
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
How do I find the second highest value. Peter Excel Discussion (Misc queries) 4 May 19th 10 03:52 PM
how do I find 2nd highest MAX in a row cruise director Excel Discussion (Misc queries) 4 August 20th 08 12:16 AM
need to find highest total [email protected] Excel Programming 1 October 24th 06 01:26 PM
Find the highest value on the column frukyy Excel Discussion (Misc queries) 5 October 4th 06 02:28 PM
Displaying the Highest Value in a user-variable range of cells Tabby Excel Programming 1 April 26th 05 09:12 PM


All times are GMT +1. The time now is 09:03 AM.

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

About Us

"It's about Microsoft Excel"