Referencing Problem

joeyjj

Board Regular
Joined
Aug 12, 2010
Messages
62
Hello All,

I would like to use the following code:

=IF(A7 = "",1, SUM(1+A7:A7))

Note that A7 refers to the cell above the current cell

however, if I delete the row above (Row 7) I get a #REF! error. My code looks like this:


PHP:
ws.Cells(iRow, 1).Formula = "=if(A" & iRow - 1 & " = """",1, SUM(1+A" & iRow - 1 & ":A" & iRow - 1 & "))"

and I would like it that if the row above is deleted that the if statement is always selecting the row above.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Before solving this for you, I have a question:

Is there a reason you are using sum(1+A7:A7) instead of simply using 1+A7?
 
Upvote 0
Lets say, you want to put a formula in A8 referencing the cell above it and add 1 to it, you can use this function:
=SUM(OFFSET(A8,-1,0,1,1))+1

If you delete a row above, excel will auto-adjust the function to make it reference the cell above it.

Hope this helps.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,275
Members
452,902
Latest member
Knuddeluff

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