Select First Cell In Range Relative To Last Cell In A Different Range

pnguyen05

New Member
Joined
Jul 25, 2023
Messages
7
Office Version
  1. 365
Platform
  1. MacOS
Hi,

Below are the requirements:

1. How do I select A4:A5 dynamically so that it'll take into consideration whenever a user deletes or adds a row? For example, if a user adds a row within that range, the code needs to recognize that and select appropriate range of cells.
2. Put the sum of the subtotals into the Total (A6) cell. This also needs to be dynamic so if a user add a row, the cell would now be A7.

Thank you

A
110
220
3Total 30
420
530
6Total 50
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hi,

Below are the requirements:

1. How do I select A4:A5 dynamically so that it'll take into consideration whenever a user deletes or adds a row? For example, if a user adds a row within that range, the code needs to recognize that and select appropriate range of cells.
2. Put the sum of the subtotals into the Total (A6) cell. This also needs to be dynamic so if a user add a row, the cell would now be A7.

Thank you

A
110
220
3Total 30
420
530
6Total 50

Or should I try using a loop?
 
Upvote 0
What determines when you put a total?
I don't really understand this question. Could you please expand? The Total would be the sum of the values within that range. So Total 50 (A6) is sum of the values in the A4:A5 range.

I realized I said subtotals in my original post, I apologize. It should be values.
 
Upvote 0
You have two totals in your example. One in A3 and one in A6.
If there were no values in the spreadsheet at all and you started adding them, at what point would you total them?

Why doesn't the total include the A1 and A2 range as well. Like I asked what determines where the totals go. Every two cells or what?
 
Upvote 0
You have two totals in your example. One in A3 and one in A6.
If there were no values in the spreadsheet at all and you started adding them, at what point would you total them?

Why doesn't the total include the A1 and A2 range as well. Like I asked what determines where the totals go. Every two cells or what?
It doesn't include A1 and A2 range as well because each total represents a different category. For example, instead of Total 1, it's Total Debit and instead of Total 2, it's Total Credit. Therefore, whatever values included from the beginning to the very last cell in the range before Total 1 would be the sum for Total 1. Then the range would "reset" for Total 2, so whatever values after Total 1 to the very last cell in the range before Total 2 would be the sum for Total 2.
 
Upvote 0
There is likely a better way to do this, but this is one way to deal with summing values in a range and then inserting rows into that range. This should handle inserting a row to be the first or last in the range to be summed. Create a named range for the first and last cells in the range using OFFSET.
Book1
A
1Header
250
310
4100
520
6200
7380
Sheet4
Cell Formulas
RangeFormula
A7A7=SUM((start_1):(end_1))
Named Ranges
NameRefers ToCells
end_1=OFFSET(Sheet4!$A$7,-1,0)A7
start_1=OFFSET(Sheet4!$A$1,1,0)A7

Hope that helps,

Doug
 
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,121
Members
453,021
Latest member
Justyna P

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