PDA

View Full Version : Enter Formula in Cell Based on Heading in Another Cell



agnesz
07-09-2008, 02:23 PM
Here's my problem. I need to enter a sum formula in columns BD & BE in the row which has "Total Excluding New Receipts / Cont % TTL" or "Page Total" in it in column B.

I'm attaching a spreadsheet which hopefully explains this better.

The row in which the two criteria "Total Excluding New Receipts / Cont % TTL" or "Page Total" appear will always vary, which is why I'd like a macro to find it for me and enter the formula in those 2 columns accordingly.

Thanks !!!!!!!!!!!!!:motz2:

mdmackillop
07-09-2008, 03:39 PM
I don't know what formulae you want but try this.

Sub AddFormulae()
Dim Rw1 As Long, Rw2 As Long
Rw1 = Columns(2).Find("Total Excluding New Receipts / Cont % TTL").Row
Rw2 = Columns(2).Find("Page Total").Row
Cells(Rw1, "BE").Formula = "=SUM(BE8:BE" & Cells(Rw1, "BE").End(xlUp).Row & ")"
Cells(Rw2, "BE").Formula = "=SUM(BE8:BE" & Cells(Rw1, "BE").End(xlUp).Row & ")"
End Sub

agnesz
07-10-2008, 07:44 AM
THANK YOU SO MUCH, this was perfect.

mdmackillop
07-10-2008, 03:56 PM
No problem :thumb
Please mark as Solved using the Thread Tools dropdown