# Thread: Code to replace formula Thanks:  1 Post #5312723 (1) Likes: 0

1. ## Code to replace formula

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  Reply With Quote

2. ## Re: Code to replace formula

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```  Reply With Quote

3. ## Re: Code to replace formula

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  Reply With Quote

4. ## Re: Code to replace formula

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","")  Reply With Quote

5. ## Re: Code to replace formula

That's brilliant thanks Peter  Reply With Quote

6. ## Re: Code to replace formula

You are very welcome. Thanks for letting us know.  Reply With Quote

## User Tag List

#### Tags for this Thread

code, column, drag, formula, ref #### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•