# Dynamically assign range names in a worksheet

Running Excel 2000 on a Windows 7 pro computer.

I don't want to have to create a separate worksheet for each stock I trade.  I am struggling with the total cell  in row 6 and row 13. (see attached spreadsheet ).

I am NOT a spreadsheet expert.  I have defined cell E6 as =sum(E2:E3).  If I add more lines below row 3 then cell E6 is not going to show the correct sum.

My understanding is if, in cell E6,  I define a range of cells starting with E2 and ending with E5 then if a row is entered above row 5 then the total will show an accurate total.  If cell E6 has a range name of Rang1 then the formula to sum any cells above E6 could be =sum(Rang1).

Cells E2,E3 and I2 and I3 have a formula in them which multiplies the quantity times the price.  I create rows near the bottom of the worksheet which have all the formatting in it (for dates, etc). Let's call this the “template rows”.  The “template” includes the total row (see rows 6 and 13 as examples ).   Then, whenever I want to add a new trade, I just copy the the template rows from the bottom, insert them below existing trades  enter the data and the subtotals and total are calculated.  I don't have to keep entering formulas to calculate subtotals and totals.

My question:  I am struggling with the range name.  When I copy the template rows, the total row has the same range name as all the other total  rows.  So the totals in the total rows are not correct. If cell E6 and E13 have the same range name the totals will not be correct.   Somehow I'd like to dynamically assign a range name so the totals of each set of trade rows is correct.  In other words, the total for IBM might have a range name of Rang1, for JNJ the range name is Rang2.  I don't want to have to manually change the range name each time I copy the template rows.

How would you design this spreadsheet to avoid having to manually assign range names?
Or may be my design is flawed and there is a better way to do this?

###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Group Finance ManagerCommented:
Your data should be in table format with one header row and no completely empty rows or columns of data. Use the SUBTOTAL Formula then you can Filter the data by Company and get individual Totals, SUBTOTAL will only sum the visible rows.

Which version of Excel are you using? If you are using one of the newer versions of Excel I would format the data as a Table
Excel VBA DeveloperCommented:
I would consider combining all the trade data together and then use Excel subtotals tool to produce the total amounts. I don't have a computer with Excel 2000 (oldest I have is 2003), but this should work.

You'll remove all the blank rows and totals, then sort by "Trade" (stock ticker) and "Date".  Then select "Data" and then "Subtotals..." from the menu.  Then, in the new dialog, select "Trade" in the list "At each change in:".  Then select "Sum" in the "Use function" list. Then click the check boxes for "Sub totals" and "Profit".  Click the [OK] button.  You can use this same sequence to remove subtotals at any time.

Until you get a handle on this, I recommend making a copy of your data sheet and apply the subtotals to that copy.

The other advantage of combining all you data is that you can then use PivotTables to achieve the same summary of the data.

Regards,
-Glenn
Excel & VBA ExpertCommented:
Instead of having the current data layout, convert your data range into an Excel Table and dump your data data for each date and trade without having any blank rows in between.
Then on another sheet, you can visualize the data as per your requirement with the help of a Pivot Table.
The advantage of an Excel Table is, the table range is self expandable once you add more data down the table and after adding the new data, right click the Pivot Table and choose refresh to reflect the new data.
That should be the easiest way considering the nature of your data.

In the attached, you will find two sheets...

1) New Data Sheet: Here you will find the Excel Table having your data.
2) Pivot: Here you can visualize your data and you can adjust it as per your requirement at any time.

See if that helps.
New-Layout.xls

Experts Exchange Solution brought to you by