ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Variable Manipulation (https://www.excelbanter.com/excel-programming/318575-variable-manipulation.html)

Arturo

Variable Manipulation
 
Im assigning cell contents to variables;

Mid = Range("A9").Value
Nor = Range("C9").Value
Uni = Range("E9").Value

While this procedure is running I need to sort those three variables low to
high then run a series of nested if statements. I do not know how to sort
the variables assigning a ranking to be used in the nested ifs. Any advise
welcome€¦

Appreciatively,
Arturo

Bob Phillips[_6_]

Variable Manipulation
 
Arturo,

How about this to put them into ascending order

Dim ary(1 To 3)
Dim temp

ary(1) = Range("A9").Value
ary(2) = Range("C9").Value
ary(3) = Range("E9").Value
If ary(1) ary(2) Then
temp = ary(2)
ary(2) = ary(1)
ary(1) = temp
End If
If ary(2) ary(3) Then
temp = ary(3)
ary(3) = ary(2)
ary(2) = temp
If ary(1) ary(2) Then
temp = ary(2)
ary(2) = ary(1)
ary(1) = temp
End If
End If

You can then use it's index as the rank

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Arturo" wrote in message
...
I'm assigning cell contents to variables;

Mid = Range("A9").Value
Nor = Range("C9").Value
Uni = Range("E9").Value

While this procedure is running I need to sort those three variables low

to
high then run a series of nested if statements. I do not know how to sort
the variables assigning a ranking to be used in the nested ifs. Any

advise
welcome.

Appreciatively,
Arturo




Sharad

Variable Manipulation
 
First of all do not use variable name Mid cause it conflicts with
function 'Mid'
use variable names iNor iMid iUni.
Then decide what will you do if two of the variables are equal or if all
three are equal.
Assuming that none will be equal you can use code like following.

If iNor iMid And iNor iUni Then
'your code to run if iNor is highest
End if

If iMid iNor And iMid iUni Then
'your code to run if iMid is highest
End if

If iUni iNor And iUni iMid Then
'your code to run if iUni is highest
End if

However you can reduce the number of statements, also run with other
conditions. If you can post exact conditions you want to satisfy, it
will help.

Sharad

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


All times are GMT +1. The time now is 06:58 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com