Max function for variables defined in code

totalnatal

New Member
Joined
Jun 9, 2010
Messages
33
Hello,

I would have created several variables within my code which are calculated solely within the code and would need to select the highest value out of these variables.

Code:
Dim a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, sa, t, u, v, w, x, y, z, aa, ab, ac, ad As Long

s = 0

Do

For n = 1 To Range("f1").Value
    
    a = Range("i3").Offset(s, 1).Value
    b = Range("i3").Offset(s, 2).Value
    c = Range("i3").Offset(s, 3).Value
    d = Range("i3").Offset(s, 4).Value
    e = Range("i3").Offset(s, 5).Value
    f = Range("i3").Offset(s, 6).Value
    g = Range("i3").Offset(s, 7).Value
    h = Range("i3").Offset(s, 8).Value
    i = Range("i3").Offset(s, 9).Value
    j = Range("i3").Offset(s, 10).Value
    
    k = Worksheet.Function.VLookup(Worksheet.Function.Edate(Range("i3").Offset(s, 0).Value, n * 12), Range("I:J"), 2)
    l = Worksheet.Function.VLookup(Worksheet.Function.Edate(Range("i3").Offset(s, 0).Value, n * 12), Range("I:K"), 3)
    m = Worksheet.Function.VLookup(Worksheet.Function.Edate(Range("i3").Offset(s, 0).Value, n * 12), Range("I:L"), 4)
    n = Worksheet.Function.VLookup(Worksheet.Function.Edate(Range("i3").Offset(s, 0).Value, n * 12), Range("I:M"), 5)
    o = Worksheet.Function.VLookup(Worksheet.Function.Edate(Range("i3").Offset(s, 0).Value, n * 12), Range("I:N"), 6)
    p = Worksheet.Function.VLookup(Worksheet.Function.Edate(Range("i3").Offset(s, 0).Value, n * 12), Range("I:O"), 7)
    q = Worksheet.Function.VLookup(Worksheet.Function.Edate(Range("i3").Offset(s, 0).Value, n * 12), Range("I:P"), 8)
    r = Worksheet.Function.VLookup(Worksheet.Function.Edate(Range("i3").Offset(s, 0).Value, n * 12), Range("I:Q"), 9)
    sa = Worksheet.Function.VLookup(Worksheet.Function.Edate(Range("i3").Offset(s, 0).Value, n * 12), Range("I:R"), 10)
    t = Worksheet.Function.VLookup(Worksheet.Function.Edate(Range("i3").Offset(s, 0).Value, n * 12), Range("I:S"), 11)
   
    u = k / a
    v = l / b
    w = m / c
    x = n / d
    y = o / e
    z = p / f
    aa = q / g
    ab = r / h
    ac = sa / i
    ad = t / j

Basically need to select the max out of the variables from u to ad.

Thank you
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Try

MyMax = Application.Max(u,v,w,x,y,z,aa,ab,ac,ad)


Also, just a tip..

When dimming multiple variables in one line...
This
Dim a, b, c, d, e As Long
Will only dim e as Long, the rest are Variant.

You must do
Dim a As Long, b As Long, c As Long, d As Long, e As Long


Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,286
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top