Max age with vba

prlondhe

Board Regular
Joined
Jan 4, 2014
Messages
54
I AM TRYING TO FIND THE MAX AGE FOR A PARTICULAR VALUE WITH THE FOLLOWING VBA CODE

THE SHEET STRUCTURE IS AS BELOW

CLIENT CODESERIAL NUMBERCLIENT NAMECOMPANY CODEPOLICY TYPEPOLICY SUB TYPEVEHICLE NUMBERDATE OF BIRTHSUM INSUREDRES. TELEPHONEOFF. TELEPHONEMOBILEADDRESSPAN CARD NUMBERPASSPORT NUMBER
clip_image002.gif

<tbody>
</tbody>

<tbody>
</tbody>


Sub MAXAGE()


Sheets("MASTER").Select
Range("A2").Select
Do While ActiveCell.Value <> ""
CD = ActiveCell.Value


If ActiveCell.Offset(0, 3).Value = "NIA" And ActiveCell.Offset(0, 7).Value <> "" Then
Range("AC2").FormulaArray = Evaluate("=MAX(IF(A:A=CD,p:P))")
ActiveCell.Offset(0, 16).Value = Range("AC2").Value
End If



Sheets("MASTER").Select
ActiveCell.Offset(1, 0).Select
Loop


End Sub

GETTING RESULT AS #NAME?

CAN ANYBODY HELP
 
Last edited:

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
I haven't read all of it but the reason you are getting name error is that the way its written CD will be thought by excel to be a named range. You need to concatenate variables and you also don't need the formulaarray part:

Code:
Range("AC2") = Evaluate("=MAX(IF(A:A=" & cd & ",P:P))")

if cd is a number

or

Code:
Range("AC2") = Evaluate("=MAX(IF(A:A=""" & cd & """,P:P))")

if text
 
Upvote 0
I think that there may be a couple of problems.

Since you are writing a formula to a cell you shouldn't be wrapping it in the Evaluate function.

Your If statement can't be evaluated so it won't return a number for the Max function.

It's not clear from your code exactly what group you are after the Max Age of. Can you create the formula in the spread sheet and post that to help determine exactly what you are trying to achieve.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,276
Members
449,075
Latest member
staticfluids

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