I know how to do this for one cell, but it needs to be with a range.
So if C12 says PayPal Fees, then E12 needs to return a formula. If C13 says PayPal Fees, then E13 needs to return a formula, etc.
If C12 says PayPal Fees, then the formula in E12 is =(E11*'-'Setup Page'!$Q$44)-'Setup Page'!$S$44
If C13 says PayPal Fees, then the formula in E13 is = (E12*'-'Setup Page'!$Q$44)-'Setup Page'!$S$44
I am running into problems for two reasons, the first reference in the formula always changes. If the formula is in row 12, the reference is E and the row above so 11. I don't know how to get it to change relative to the row the formula is in.
The other reason is I don't want to have to say if C12 changes then this; if C13 changes then this; etc. one at a time because it is a long range. C12:C190. So anytime just ONE cell in that range changes, then the E column in that row needs the formula.
Below was what I knew how to do. I know the code is wrong, but it worked in the sense that when I changed C12 to PayPal Fees, it did put the formula in E12. But in my code, the first formula reference is stagnant and as mentioned it needs to change. Then it, of course, tried to check all the other cells in the range, which were currently blank so it killed the page.
![]()
Private Sub Worksheet_Change(ByVal Target As Range) Dim rngInvoiceCategory As Range Dim returnAmount As Range Dim c1 As Range Dim ws As Worksheet Set ws = ActiveSheet With ActiveSheet Set rngInvoiceCategory = ws.Range("C12:C190") Set returnAmount = ws.Range("E12:E190") For Each c1 In rngInvoiceCategory If c1.Value = Sheet1.Range("N44") Then ws.Range("E12").FormulaR1C1 = _ (Note: I can't really say range E12 because that changes. If C12 is the one saying PayPal Fees, then it is E12. If C13 is the one saying PayPal Fees, then it is E13 etc. "=(R[-1]C*-'Setup Page'!R[32]C[12])-'Setup Page'!R[32]C[14]" (Note: I need that first reference to change based on the row it is in)' Else End If Next c1 (Note: I am sure a loop here is wrong since only one will change at a time). End With End Sub
Bookmarks