totalnatal
New Member
- Joined
- Jun 9, 2010
- Messages
- 33
Hello,
I have the following code:
Basically I want the maximum out of the above variables from u to ad. However, if in n = 1 say u was the max, then for subsequent n(2,3...) never include that variable in the Max function again.
How would you go about doing this?
Thank you
I have the following code:
Code:
Sub X()
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 - 1
v = l / b - 1
w = m / c - 1
x = n / d - 1
y = o / e - 1
z = p / f - 1
aa = q / g - 1
ab = r / h - 1
ac = sa / i - 1
ad = t / j - 1
Range("t3").Offset(s, n).Value = Worksheet.Function.Max(u, v, w, x, y, z, aa, ab, ac, ad)
Basically I want the maximum out of the above variables from u to ad. However, if in n = 1 say u was the max, then for subsequent n(2,3...) never include that variable in the Max function again.
How would you go about doing this?
Thank you