Variable Manipulation

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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)
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top