# Code to replace formula

#### ExcelRoy

##### Well-known Member
Hi all,

I have the following formula that searches to find the latest row of data

Column C is the date
Column F is the job ref
Column G is the article ref

IF(AND(MAX((\$C\$12:\$C\$10023*(\$F\$12:\$F\$10023=F322)*(\$G\$12:\$G\$10023=G322)))=C322,C322<>""),"Latest","")

I have this on a long list and have to drag down the formula to 7000, plus rows

Is there a way to replicate this as code as to not slow up the sheet when typing?

Many thanks

### Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

#### alansidman

##### Well-known Member
If you are trying to find the last row in the column C, then the following code will work

Code:
``````Sub FindLast()
Dim lr as long
lr = Range("C" & rows.count).end(xlup).row
Msgbox ("Last Row is " & lr)
End Sub``````

#### ExcelRoy

##### Well-known Member
Hi Alansidman,

Apologies here but I may have mislead you with my requirements

The formula looks for the last entry for each job ref and shows this row by "Latest"

there may be many different entries with the same job refence but would like to see the latest entry as a quick reference

Thanks

#### Peter_SSs

##### MrExcel MVP, Moderator
Before moving to code, you could try a formula like this. For me, it is about 5 times faster than your existing formula.
I have assumed that the formula quoted actually starts in row 12 with references to F12, G12 and C12
If that is so, you could try this in row 12 instead and copy down.

=IF(COUNTIFS(F12:F\$10023,F12,G12:G\$10023,G12)=1,"Latest","")

#### ExcelRoy

##### Well-known Member
That's brilliant thanks Peter

#### Peter_SSs

##### MrExcel MVP, Moderator
You are very welcome. Thanks for letting us know.

1,102,218
Messages
5,485,442
Members
407,501
Latest member
DannyLee

### This Week's Hot Topics

• Finding issue in If elseif else with For each Loop
Finding issue in If elseif else with For each Loop I have tried this below code but i'm getting in Y column filled with W005. Colud you please...
• MsgBox Error
Hi Guys, I have the below error show up when i try and run my macro in File1 but works fine if i copy and paste the same code into file2. [ATTACH...
• CELL FORMAT - IF CONDITION
My Cell Format is [B]""0.00" Cr". [/B]But in the cell, it is showing 123.00 for editing. (123 is entry figure). (Data imported from other...
• Show numbers nearly the same
Is this possible. I have a number that can change very time eg 0.00001234 Then I have a lot of numbers 0.0000001, 0.0000002, 0.00000004...