Setup an Excel template so calculations are not dependant on a specific number of columns / rows - vba

Problem Statement:
I'm creating a template for multi tiered complicated calculations in MS Excel that depend on a few input "n x 3" matrices.
It is really difficult to redesign the 15 sheets or so (200 ~ 300 lines each) every time I have a different "n" where "n" ranges from 3 to 900.
Goals:
I'd like to input the number of "n" in a cell subsquently changing all the other sheets in the workbook accordingly.
Avoid VBA as much as possible
How can I achieve these goals?
Note: I'm willing to answer any questions or comments concerning my issue
EDIT
"n" represents the number of columns / rows, if n = 3, all calculations will be for a 3 x 3 matrix. If n = 500, all calculations will be for a 500 x 3 matrix.
I want Excel to do the expansions / contractions of the rows automatically, so i do't have to do them myself accross hundreds of tables

In Excel 2007 turn your data matrices into tables.
This can be done by clicking on a matrix and then on the Insert tab select Table. The keyboard shortcut for this functionality is Ctrl-L or Ctrl-T. Multiple tables can exist on the same worksheet.
Once your data is marked as a table, the table will dynamically expand when new data is added.
Each table is automatically given a name, starting with Table1. The name can be change via the Table tools - Design tab.
In formulas each table can be referenced by it's name.
=SUM(Table1)
Each column heading in the table is also usable in formulas.
=SUM(Table1[Column1])
In versions of Excel prior to 2007, 'Dynamic named ranges' can be used.
These can be created via the Insert - Name - Define menu.
Give the 'Dynamic named range' a name (e.g. Table1) and enter a formula similar to the following assuming your matirx starts in cell A1:
=OFFSET(Sheet1!$A$1,1,0,COUNTA(Sheet1!A:A)-1,3)
If your matrix starts in cell D10 the formula would look like this
=OFFSET(Sheet1!$D$10,1,0,COUNTA(Sheet1!D:D)-1,3)
This formula excludes any column heading in the matrix. It selects data on a 'n x 3' basis.
In formulas each 'Dynamic named range' can be referenced by it's name.
=SUM(Table1)
You will need to review the layout of your worksheet as the dynamic named range works out it's number of rows by counting all items that appear in the first column of data.
If you have cells populated above and/or below your matrix they will be included in the calculation and the 'Dynamic named range' will include rows below your data matrix.
To see which cells are included in a 'Dynamic named range' or table press F5 and type in it's name, then click on OK.

Create defined names (Insert - Name - Define) that use OFFSET and COUNTA to make dynamic ranges. Instead of
=SUM(A1:A300)
use
=SUM(MyRange)
where MyRange is
=OFFSET($A$1,0,0,COUNTA($A:$A),1)
See also

Instead of calculating against A1:A300, you can calculate against A:A, which is the entire column.
You may have to bear in mind that you don't want other stuff in that column when you design your layout.
In more recent version of Excel, you can select sets of data and format them as a table, in which case you can use the table column, for example Table1[Column2].

Related

Match, pull and add numbers from different cells on a different sheet

I have data on 'JobSheet1' in Column D, I have Invoice Numbers in ascending order (some are repeated for different products on same order), in Column E, I have amounts i.e £50.00.
On a second sheet 'InvoicesSheet1' in Column B, I have the invoice numbers and Column C is where I would like the total for each invoice number to appear.
Can anyone help with very simple VBA or a formula that will search for the Invoice Number its sitting by in 'JobSheet1' Column D and add all the matching invoice number totals from Column E.
Scott Craner is right, with the schema you described, you will get the result you want entering into cells Ci:Cj (where "i" and "j" are
the start and end of your table, respectively):
=SUMIFS('JobSheet1'!E:E,'JobSheet1'D:D,B{i...j})
If this doesn't work, likely issues you need to watch out for would be:
Sheets are not named exactly as you typed here. Maybe they have a leading or trailing space.
Your copy of Excel/Windows may be set with a different regional setting, which requires that formula parameters be separated by semicolons (;) instead of comas.
Your invoice numbers may not be typed precisely the same in the two different formulas.
Your amounts in column E may not be stored as numeric values. You can test for this by selecting a few values from column E - if excel doesn't show their sum and average in the bottom right corner, they are stored as text and you can't perform math operations on them.
I'd need to see your data to see what could be the issue, but that's not what this forum is for - Try constructing a new table with dummy data set up exactly as you described it here and try using this formula, to verify if it works. Then, adjust accordingly as needed.
Assuming you're first invoice number in InvoiceSheet1 is in cell b3, you can use:
=SUMIF(JobSheet1!D:D,InvoiceSheet1!B3,JobSheet1!E:E).
If it's in another row, replace InvoiceSheet!B3, with the relevant cell where your data starts. Copy down the formula for the other invoices
SUMIFS is not necessary with just one lookup condition.
I solved this by amending the SUMIFS suggestion from ScottCraner and this is what I ended up with
=SUMIFS(Jobs!K:K,Jobs!A:A,D3)+SUMIFS(Jobs!L:L,Jobs!A:A,D3)
Does the job!

Need VBA script to extend Excel table every week

The problem is as follows: I have several tables in Excel with given number of raws and dynamic number of columns (each week a new column should be added, currently I'm doing it manually). I want to automate it and create a script that will extend every raw range to the next column (namely the range from A2 to C2 should become from A2 to D2), and so on (such that running script N times will result in extending a table to N columns further). By "extending" I mean extending formulas, since each cell in my tables contains any formula. Is there any way to do it via VBA?
I can't just record the corresponding macro because I have now idea how to specify that I don't want to link it with any specific range, but instead always extend just to one column right.
Any help and examples will be very appreciative.
You dont need VBA to do this. Use dynamic defined names and reference them in your formulas. For example, if you add a named range and add this in the refersTo dialog
=OFFSET($A$1,0,0,COUNTA($A:$A),COUNTA($1:$1)
your range will automatically expand from cell A1 (as long as there are no blank cells in column A or Row 1). You can then use that named range in your formulae.
More here http://www.excel-easy.com/examples/dynamic-named-range.html

Excel - Can not compare two spreadsheets

I have gone through V-look-up guides online but I can not find one that explains what I am looking for. I am trying to avoid manual checking.
What I have:
Two sheets, Sheet 1 and Sheet 2. Both sheets have the same column names (A1:G1) with multiple rows.
Sheet 1 contains my spreadsheet where I update daily. Sheet 2 is the same spreadsheet that is imported from a application (but has hourly updates). Data can change in each row (for some columns) along with additional added/deleted rows. The data is text, dates and numbers (mixture of both too).
I want to run a formula to highlight the changes on sheet 1 (grabbing the updates from sheet 2. Once I find out the formula works correctly, I would like to know how to replace the Sheet 2 updates onto my spreadsheet (Sheet 1).
I am looking for a formula outside of creating a macro (worst case scenario).
Currently I have the following vlook up formula:
=VLOOKUP(A1,sheet2!$A:$A,1,FALSE)
When I run this in another column (lets say in H1 in Sheet 1), it will display "N/A" if that column (A1) in Sheet 2 is not the same. If it is the same, it will write out the column name.
When I use the following formula highlighting all the cells in Sheet 1, I get a values error:
=VLOOKUP(A1:G33,Sheet2!$A:$G,1,FALSE)
How could I apply that formula to the whole spreadsheet (I guess it would apply to both sheets) and have it highlight records in my spreadsheet (Sheet1). Could it also highlight rows that are missing or added?
The data in Column 1 and 2 would never change (they are ticket numbers). Only change that can apply is if ticket is closed, so when I import the updated spreadsheet that row isn't there anymore. If you think there might be a better way to tackle this down, I would like to hear.
Please let me know if I am not clear.
Here are some example screenshots:
Just in case, the formula for the totals are (adjusting the columns for each):
=SUBTOTAL(3,INDEX(C:C,2):INDEX(C:C,ROW()-1))
Sheet 2 is setup very similar. When I import it into excel, the columns are the exact same as Sheet 1, the only difference can be more/less rows (along with the updates for each row).
You can use conditional formatting.

Excel add up values in one cell based on mutliple results from one look up value

hope you are all doing well today! I've been working on a spreadsheet that tracks invoices and the hours recorded for each one. Each invoice has multiple entries with different numbers of hours for each entry, all with the same reference number which combines the project number and the invoice number. For example, for Invoice #1 of project CZ23, the reference number would be CZ23-1. Invoice 2 would be CZ23-2, and so on. This is located in Column I, while the hours are located in Column H in a sheet named "Document Data".
Now I have another sheet that tracks the hours called "Summary". What I want to do is have cell B28 of "Summary" add up all the hours from CZ23-1 from "Document Data". Since I barely know any VBA, I don't have code but I'll display the situation here:
In this case, cell B28 on "Summary" would be 15 (all the CZ23-1 hours added up: 2+5+1+7), while B29 would be 7 (all the CZ23-2 hours added up: 4+3) and so on. It doesn't necessarily have to be B28/B29, but just as a reference I've used those cells. Thank you so much for your time - hope I was able to explain everything well.
Best way to do this would be to create a pivot table.
1. Select a cell inside your data and then on the insert tab select pivotTable.
2. A "Create PivotTable" box will pop-up. Verify that your data is captured in the Table/Range. Also, you can choose if you want to have the table appear on a new sheet or the existing sheet.
3A. In the "PivotTable Fields" box, you can drag "Reference" to the Rows box and then drag "Hours" to the Values box. This should default to Sum and should add up all the Hours by Reference.
3B. Occasionally the Values box will default to Count. To change this to SUM, you can select cell B4 or B5 (See Below). Right click and select Value Field Settings. When the "Value Field Settings" box pops-up, you can select Sum on the "Summarize Values By" tab.
It sounds like you want the sql concept of 'group by' on column 'Reference'
In excel you can do this by using pivot tables
You will find pivot tables in the toolbar at Insert-->Tables-->PivotTable

Splitting data between worksheets depending on status of Column A

I have been asked to create a database of volunteers in Excel. The main worksheet (called Data) holds all the information – names, addresses, numbers, reference checks, placements, supervisors, etc. What I am trying to achieve is for the relevant information to be moved from one worksheet to another when the status of the person changes.
There would be 5 categories which the volunteers would fall under (column A labelled ‘Status’)
PROCESSING
ACTIVE
ON HOLD
BARRED
STOPPED/RETIRED
What I want to get is a live database so the information would appear on a relevant worksheet whenever the status on the main spreadsheet changes , but I only want some information to show depending on the category…
Each Worksheet would contain columns A-F from the ‘Data’ worksheet and in addition:
Processing would contain columns X-AE
Active: AF-AW
On Hold: AZ-BC
Barred: AX-AY
Stopped/Retired:- BD-BH
I have searched and searched again but I know nothing about Macros (and my IT department is unable to help) So my question is – is this doable and if so is anyone able to help me?
I hope I am making sense and if not I can email across the dummy database with some made up names to show what it is I am trying to create
You can do this using array formulae. This link shows a simple example which provides the basic formula (explained in detail in the linked article)
=INDEX(range,SMALL(IF(col=value,ROW(range)),ROW(1:1)),COLUMN(A2))
Where range is the range of all your data from your main worksheet and value is the value you want to screen for (this changes for each of your sheets) and col is the column on your main sheet that you want to check the values of. Note it is an array forumla so you have to press control+shift+enter after typing in the formula as explained at the bottom of the link.
You will notice that I have changed the formula to say COLUMN(A2) instead of 2. This is so that you can drag the formula across the columns as well as down the rows. You might need to make this COLUMN(A2)-x where x is an offset because your data don't start in column A.
Note that the same applies for the ROW(1:1) part, if your range doesn't start in row 1 then you will need to offset this by some value as well (i.e. something like ROW(1:1)-y)