Table Auto-Expand Changes Formula Range - excel

The attached image is a table in a workbook I'm working out of. It's pretty self explanatory if you read the column headers. The Week number has a simple count formula to count the number of Week Ending dates in the range from the top of the data to that specific row. i.e - for Row one of the data the count range is $B$2:B2, for row 27 of the data the range is $B$2:B28
The issue is that when a new row is added the range for the new row is correct, $B$2:B29, but the range in row 27 changes to the exact same range, hence the 2 rows with a 28 count. I can't ferret out an answer from google and as far as Excel is concerned it's formula is fine... Can anyone provide some insight on this?
The formula is =COUNT($B$2:B##) depending on what row its on for those who want to see it.

Use table references instead of cell references:
=COUNT(Table1[[#Headers],[Week Ending Date]]:[#[Week Ending Date]])
This will count from the header down to the current row.

You could use INDEX:
=COUNT($B$2:INDEX(B:B,ROW()))
The issue is in the old last row Excel thinks that you want to include the whole data set as it refers to such. So when the new row is added it adds to the formula automatically.
With the formula above it will not do that.

Although this question has already been answered/solved, will leave an alternative approach in case it is of use to someone else:
=ROUNDUP((B2-$B$2)/7,0)+1
This assumes that the date in B2 is effectively "week 1".
I agree with this answer, in that it is preferable to use Excel table nomenclature where possible.

Related

Vlookup DragDown

Im beginning a new job in a fabric. Actually, for each product, they have a excel file with the product operations in different sheets. I saw that a real problem, it takes a lot of time, and every time we should have to change the layout of the order, we are going to need to change a lot of excel files.. It will take forever and I think I can help on that.
So, my idea, is making a sheet with all the products and their operations and formulas:
Then, I have maked another sheet with the order fabrication with all the operations needed to make the product:
Every product will have an ID and im using in all cells the vlookup function from the ID:
=IFERROR(VLOOKUP($K$3;'estrutura-artigos2'!B8:V71;5;FALSE);"")
And Its Ok like you see on the last image, the problem is when I change the ID it doenst change like it should be (on my head):
Can anyone help me on this problem? I want it to change always to the ID I insert, and dont continue with the new ID.
=IFERROR(INDEX(Sheet1!E:E;MATCH(1;($K$3=Sheet1!$A:$A)*(COUNTIF($A$6:$A6;Sheet1!$E:$E)=0);0));"")
As your examples show no columns or rows I made my own. Please modify the formula to your ranges. Sheet1 is your datasheet.
Column A in Sheet1 is the column holding the ID in your datasheet.
Column E in Sheet1 is the column holding the 'op' in your datasheet (between qty and machine column).
Counting starts at row 6 in my example, but modify it to the cell above where you put your formula.
Enter the formula with ctrl+shift+enter as it is an array formula.
Change the index for the different results, but keep the rest of the formula unchanged.
Updated answer based on the visibility in rows and columns:
In A13 use =IFERROR(INDEX(datasheet!F$8:F$72;MATCH(1;($K$3=datasheet!$B$8:$B$72)*(COUNTIF($A$12:$A12;datasheet!$F$8:$F$72)=0);0));"")
Match returns the row number of the first match where datasheet column B equals the value in $K$3 and where the values of datasheet column F don't equal any of the previous results of this formula in column A (above the current row number)
The result is the row number that needs shown from the indexed column.
For the issue im having, this is as far I already went thanks to #P.b:
The problem im having is that the formula Im using goes right no operation 20, instead going to the operation 1, any idea how to fix this?
Formula using on the A13 = =IFERROR(INDEX(datasheet!F:F;MATCH(1;($K$3=datasheet!$B:$B)*(COUNTIF(datasheet!$B$8:$B71;datasheet!$F:$F)=0);0));"")

Trying to correctly duplicate formulas keeping same cell range but adjusting date ranges

I'm trying to help someone with an Excel spreadsheet of sales figures. I hope this explanation is clear. She has a worksheet for each category of items she sells, such as clothing, shoes, furniture, &c. Each worksheet has a column, G, for Date Sold, and the data is in Date format.
On a summary worksheet, she wants to aggregate and analyze the data, and one thing she was doing manually was counting the number of sales of each category for each month (sometimes zero).
I helped her write a formula to pull the count from the clothing worksheet, for the month of March 2019 into a cell on the summary worksheet:
=COUNTIF($CLOTHING.G3:G502;">2/2019")-COUNTIF($CLOTHING.G3:G502;">=4/2019")
This correctly yields 5. Cool. But that is just one month, and we need twelve for each year, for multiple years, and we have six categories. So we'd rather not hard-code each formula every time we need a count.
When we tried to copy the formula into cells below (for April, May, etc), hoping it would adjust the dates, it wrongly adjusted the cell range to G4:G503. The cell range shouldn't change; the months should advance, but they did not change.
We've been trying different suggestions we found online, such as naming the range G3:G502 but it didn't like that. We got an error.
We both (obviously) have a limited knowledge of Excel. Please let me know what we're doing wrong OR if there is a better way to approach this, and how to do it step by step. Please ask any questions if my explanation is not clear.
Using your formula I would adjust it as follows:
=COUNTIF($CLOTHING.G$3:G$502;">="&DATE(2019;row(1:1);1))-COUNTIF($CLOTHING.G$3:G$502;">"&EOMONTH(DATE(2019;row(1:1);1),0))
Note the addition of the $ to the cell reference. This keeps either the column or row from change when a cell is copied.
Row(1:1) will return 1 in the first cell it it entered into and as it is copied down will increase by 1. Therefore it is important not to copied it down more than 12 rows from its initial entry point.
Note the year in the date is hard coded. Alternatively the year could be placed be place in a cell and a reference to that cell could be used in place of the hard coded year. That way in subsequent years, you would just change the value in the cell instead of changing your value in the hard coded formula.
Note this solution assumes January for the first cell and months following sequentially to December for the 12th cell.
I my system is configured to use , as separators instead of ; so it is possible I may have made a mistake with those in my edits.
Alternatively you could look at COUNTIFS. It is similar to COUNTIF but requires all entries to be TRUE for an entry to be counted.
=COUNTIFS($CLOTHING.G$3:G$502;">="&DATE(2019;row(1:1);1);$CLOTHING.G$3:G$502;">"&EOMONTH(DATE(2019;row(1:1);1),0))

Countifs for longer range

I am currently using Countifs to add up an amount of registrants that have a gender criteria and birth year criteria.
Formula:
=countifs(sheet1!N4:N90,”male”,sheet1!F4:F90,”1990”)
This works and shows me the amount of males born in 1990. I’m currently running this formula in sheet2. Every day or two I’ll import the registrations and the range will grow past row 90. Is there a way to write the formula that will adjust the result when I paste in new registrants?
Currently I can’t extend the formula past 90th row. And with all the birth years, it’s be great if I didn’t have to edit the formula manually every time I update the list.
There are at least 4 ways to do it:
Use "N:N" and "F:F" instead of "N4:N90" and "F4:F90". It will refers to the whole column.
Formula: =countifs(sheet1!N:N,”male”,sheet1!F:F,”1990”)
Use VBA (I'm not going to explain that now because I guess it's not what you want)
Use Dynamic Named Range like explained here https://www.excel-easy.com/examples/dynamic-named-range.html.
It applies to range without empty values (the height of the range is based on the number of values in the column and adding them to the row of the first row of your range (offset base).
We don't know how your registrant records on sheet1 look. I guess that on column A you have a record ID or something else that it's not empty until the table ends. While on column N and F you can have empty values (e.g. registrant year or gender is not mandatory).
So you have to create a named range 'Genders' that will refers to =OFFSET($N$1,0,0,COUNTA($A:$A),1) if you have not an header row. If you have one header row you have to start the offset from N2, etc. =OFFSET($N$2,0,0,COUNTA($A:$A),1).
You have to do the same thing for the birth year and use these named ranges in your formula, like:
Formula: =countifs(Genders,"male",BirthYears,"1990")
Convert the range of records to a table, selecting it and going to Insert-->Table. You'll be able to use table field names in the formula (Solution based on Ron Rosenfeld' comment)
=countifs(Table1[Gender],"male",Table1[BirthYear],"1990")

How do I reference the last row in a named Excel table?

I am currently trying to format one column of my table so that if there are any names that match in another column, the cell in the original column will be highlighted. Here's an example of what I mean:
Row 10 has a prerequisite of the M6A1. However, row 11 has a name of M6A1. I would like the M6A1 in row 10 to be highlighted.
To do this, I figured I would use COUNTIF, with the range from the current row (10 in this case) down to the bottom row (14). I don't want to hard-code in 14 however, as the list length will change. Therefore, I thought that I could just call the last row in the table, but that's not a feature apparently. I would like to know either how to dynamically reference the last row in this table, or if there is a better way to do this.
If you consider using built-in Excel functions you can get the last row of the table or named range this way:
=ROW(NAMED_RANGE or TABLE_NAME)-1+ROWS(NAMED_RANGE or TABLE_NAME) - for the last row of the table;
=ROW(NAMED_RANGE or TABLE_NAME)-1+COUNT(NAMED_RANGE or TABLE_NAME) - for the last record in the table.
To get the last row of your table, use Range("A1").End(xlDown).Row, provided your "A" column does not have any blank cells. If it does, a better way to do it is to use Range("A1000000").End(xlUp).Row.
The .End(Direction) method goes to the last cell before a blank a cell in a given direction (Up, Down, Left or Right, preceded by xl), starting from the specified Range, and the .Row method gets the row number of a given Range/Cell.
I would suggest this code:
lastRow = ws.Range(affectedTable).Row + ws.Range(affectedTable).Rows.Count - 1
Expanding on a previous answer with what worked for me. Below is another solution that does not require VBA but will return the last populated row instead of the last row of the table area.
COUNT(TABLE_NAME) will return the total number of filled cells in the table. If there are blank cells, this may not work correctly.
Since we are trying to count rows, it makes more sense to use only one column of the table which will always be filled (in many cases the first column). Using the built-in COUNTA function, we can count only the cells that have a value. Use structured references to specify a single column in the table or named range:
=ROW(TABLE_NAME)-1+COUNTA(TABLE_NAME[COLUMN_NAME])
If you want that inside the table (totals cell for example), just use offset (no empty rows of course):
[code]=OFFSET(tblName[[#Totals],[ColName]],-1,0)[/code]
If it is out of table, there are many good solutions.

Excel formula for earliest date ONLY when value a second column matches the value a third column

SOLVED - No further efforts required. Formula below.
I am trying to create a function that works across two worksheets to find the earliest date if it matches criteria in 2010. The goal is to continuously see the most out-of-date item that has the same "name", so that it can be reviewed and made current. The process repeats.
The first worksheet produces a summary for a product. The second is a collection of metadata for the product. I would like to find a function that compares a column to a single cell on the first worksheet and produces the earliest date from the rows on the second worksheet that match.
Here's the basic idea:
IMGUR LINK TO SCREENSHOT OF CONCEPT. Sorry. Doesn't seem to let me embed.
It is important that if a 4th AA is added, the formula finds it and continues to account for it.
I've tried some combinations of IF, VLOOKUP, and MINA or MIN, but can't seem to get it to work.
The closest I've gotten is
=MIN(IF(A11:A18=A3, C11:C18, broken).
But that doesn't seem to work when I raise the amount of values in the arrays.
Any help would be appreciated. Thank you.
SOLVED: Function was correct. I forgot to use "ctrl+shift+enter". Keeping post active for others to reference.
Try
=MIN(IF(A3=Sheet2!A:A,Sheet2!B:B)) entered as an array formula (Ctrl+Shift+Enter)...This formula assumes that your text criteria is in Column A of Sheet 2 and your date criteria is in Column B of Sheet two. This formula would be pasted in cell B3.

Resources