How do I display a number range when a number is entered? - excel

I have a spreadsheet of clients and columns for their names, addresses, and ages. I'd like to display an age range in the column when their specific age is entered. For example, if Tina is 32, I'd like the "age" column to show "30-35" instead of 32.
Is there any way to do this?

The simplest way may be to create a lookup table in which 30-35 is in a cell immediately to the right of 30 (with the next row something like 36 and 36-40) and then rely on VLOOKUP's inexact matching, where if a value (eg 32) is not found the next lower is chosen, because of the ascending order of the table. So something like:
=VLOOKUP(32,table,2)

assuming you have the following three columns name, address, age
you could create a fourth column and copy + paste in the following formula:
=IF(ISNUMBER(C1),INT(C1 / 5) * 5 & "-" & INT(C1 / 5) * 5 + 5, "")
Once pasting the formula into the new column you can drag-down to extend it for all rows. You can then right click on the header of the age column and select Hide to be left with only the age range.
The above formula assumes column C is the age, and will display the age range only if a number is entered.

Related

How can I average the last n number of rows when using a Average(Index, match formula)?

I have two sheets one has a table with sets across the top of the table and daily km for each set the second sheet has set numbers in column b, I wish to find the daily average for the last 6 months (so 182 days) for each of the sets and return the value in column F.
Sheet 2
sheet 1 - Table
I have used the following formula to average the entire column
=AVERAGE(INDEX(Table1[[H9003]:[H9043]],0,MATCH('FA Forecasts'!B5,Table1[[#Headers],[H9003]:[H9043]],0)))
However I only want to return the average of the last 182 rows of the table to the corresponding set number - and each time a new line is added I only want the last 182 rows.
I'm not sure what I can do to achieve this - any advice would be most appreciated.
If you have Excel 365 you can use this formula:
=LET(indexSetNumber,MATCH([#[Set Number]],tblSheet1[#Headers],0),
filterByDate,FILTER(tblSheet1,tblSheet1[Date]>=LARGE(tblSheet1[Date],cntDays)),
filterBySet,INDEX(filterByDate,,indexSetNumber),
AVERAGE(filterBySet))
I like "readable" formulas - this one reads like this:
indexSetNumber: returns the column index of e.g. H9003 --> 5
filterByDate: returns the rows with Top "cntDays" dates. I am using a parameter cntDays in C2 - for this example I chose 2, but you would put 182.
filterBySet: returns column indexSetNumber from filterByDate
from these values AVERAGE is returned.
This might also work (assuming C2 is =TODAY()):
=AVERAGEIF(Table1[Date],">" & C2 - F2,INDIRECT("Table1["& 'FA Forecasts'!B5 &"]"))
Using AVERAGEIF formula :
Table1[Date] : returns the "Date" table column (sheet 1)
">" & C2 - F2 : "date more recent than Today-182 days"
INDIRECT("Table1["& 'FA Forecasts'!B5 &"]") : returns the table column (sheet 1) which header match with Set Number in the current row (sheet 2)
Basically return the average for kms in the past 182 days for the Set Number of the row.

Auto Increment the value of a cell based on an adjacent sell value plus search last number increment by 1

Ok I have 2 excel columns
1st column A "Workstream", is a data list with three numbers as a dropdown. 1,2,3
2nd column B "ID", would like to auto-populate based on the selection made from the left adjacent cell + perform a lookup to get the MAX number in the current column and ADD by 1.
For Example:
Workstream
ID
1
W1-001
1
W1-002
1
W1-003
1
W1-004
2
W1-001
1
W1-005
2
W1-002
So when a user selects from the drop-down in column A then Column B auto-populates with something like this
="W"&A:1&"-"
However, in order to complete the value, it needs to do the following:
="W"&A:1&"-" Search for the Max Record in Column B that starts with 1 or whatever value was entered into Column A, then include the next number based on the MAX value selected in Column A
So in the above example, let's say I Enter "2" in column A, then the value that auto-populates in column B would be
| 2 | W2-003
or if I selected 1 from column A given where we left off then the value that would auto-populate in column B would be:
| 1 | W1-006
If I am understanding correctly and you want the format to be "W" followed by number of the workstream (as inferred from the text of your question) try:
="W"&A2&"-"&TEXT(COUNTIF(A$2:A2, B2), "000")
If instead you want the output exactly as shown in the picture you provided, it's even easier:
="W1-"&TEXT(COUNTIF(A$2:A2, B2), "000")
EDIT: You might consider pre-dragging the formula to all the rows that you think have the possibility of being impacted so that you don't have to drag the formula each time you add a row. In that case, try:
=IF(A2="","", "W"&A2&"-"&TEXT(COUNTIF(A$2:A2, B2), "000"))

How to get maximum number and name from 2 columns? (Excel)

I have this (example):
Luffy 320
Coby 350
Zoro 180
Now I want to show the max from this info, with number and text (in seperate cells) like this:
col 1 col 2 col 3
1st 350 Coby
2nd 320 Luffy
3rd 180 Zoro
The 2nd Column no problem with the MAX() formula.
For the 3rd column to get the text I've tried the MAX(...) and INDEX(...) formulas but nothings working ...
Can anyone help me?
You first need to get which value is the largest, second largest and so on.
You can use the function LARGE(range, n) for this.
So in your col 2 use this formula:
=LARGE(B:B,1)
=LARGE(B:B,2)
=LARGE(B:B,3)
Assuming B is the column with the values.
Then we need to match this value and get the name
=INDEX(A:A,MATCH("the above calculated cell",B:B,0))
With the above calculated cell I mean the LARGE function cell. And assuming column A is the column with the names.
This should give you a dynamic table that will update when values or names change.
I'm not sure how you manage to get that column 2 using MAX formula since it only outputs the largest number of the inputs and thus can't output 2nd and 3rd position.

Highlight exceeding limit in VBA

line customer product OrderQty TotalQty
1 A 11111 5 10
2 B 11111 5 10
3 c 11111 5 10
4 A 22222 5 20
5 B 22222 5 20
6 C 22222 5 20
I have a table as shown above.
I want to to highlight the lines when OrderQty is bigger than TotalQty for a product.
OrderQty represents the number of units requested for in that order, TotalQty represents total units available to fulfil all orders.
In this example, I want to highlight lines 1,2,3 as product 11111 OrderQty 5+5+5=15 is bigger than TotalQty 10.
Is there a way to automate this in VBA? I suspect using Sumifs but I can't wrap my head around..
Thanks in advance!
You don't need VBA for this. Assuming your table above starts on row 1 with Line in column A and TotalQty in column E; put a unique list of Product in column F and in cell G2 put the formula:
=IF(SUMIF(C:C,F2,D:D)>VLOOKUP(F2,C:E,3,FALSE), "Over", "Equal or under")
The SUMIF sums OrderQty for each Product, the VLOOKUP returns TotalQty for the first instance of each Product found in the table. You can then use conditional formatting to highlight rows if required.
If you did go the VBA route, I'd probably put the table into an array, create a dictionary of Product with a value for OrderQty, and either loop on the array and sum values, or loop on the dictionary keys and call the sumif worksheet function.
Maybe something like this ?
Sub test()
Range("A:E").Interior.Pattern = xlNone
Range("C1:C7").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("AA1"), Unique:=True
Set Rng = Range("AA2", Range("AA100000").End(xlUp))
For Each Prod In Rng
Set c = Range("C:C").Find(Prod.Value, lookat:=xlWhole)
Tot = c.Offset(0, 2).Value
Ord = Application.SumIf(Range("C:C"), Prod.Value, Range("D:D"))
If Ord > Tot Then
For Each cell In Range("C2", Range("C2").End(xlDown))
If cell.Value = Prod.Value Then
Range(cell.Offset(0, -2), cell.Offset(0, 2)).Interior.Color = 65535
End If
Next cell
End If
Next Prod
Range("AA:AA").ClearContents
End Sub
Or if you choose without VBA, use Conditional Formatting.
Select the range you want to be highlighted
Click Conditional Formatting ---> New Rule
Choose "Use a formula to determine which cells to format"
Type =SUMIF($C:$C,$C2,$D:$D)>VLOOKUP($C2,$C:$E,3,FALSE) in the formula box
Click Format button, then do the formatting as you want
Click OK, Click OK.
[Good day Kyle,
Is this what you are trying to do. This is only simple solution but can help you.
I used a helping column for your criteria you mentioned. I used sumifs. You can modify it to your style and needs. I used conditional formatting to highlight cells.]1
First, streamline your table, divide into two tables:
line, customer, product, OrderQty in one table.
product, TotalQty other table.
Assuming {product,TotalQty} in 'Sheet 2', and the other table in 'Sheet 1', then add a column in second table (C column in sheet 2) 'OrderQty>TotalQty' and insert formula in the cell below it, as follows:
=IF(SUMIF(Sheet1!$C:$C,$A2,Sheet1!$D:$D)>$B2,"Yes","No")
Drag or copy-paste the formula to remaining product rows.
Screenshots:

Conditional Unique ID for each record excel

I have two values in different columns. Column A have Department name i.e. HR, Admin and Ops. and column be have date. I want Unique ID in column C based on Combination of Column A & B and Unique number at the end.
Unique ID: HR-Aug-16-1
Admin-Aug-16-1
this number will be repeat till the combination of Column A and B repeated 50 times after 50 times last value will be increased by +1. i.e.
HR-Aug-16-2
Admin-Aug-16-2
Right now I am using formula,
=A1&"-"&TEXT(B1,"mmm-yy")&"-1"
In C1 as a standard formula,
=A1&"-"&TEXT(B1,"mmm-yy")&CHAR(45)&INT((SUMPRODUCT(--(A$1:A1&TEXT(B$1:B1, "mmm-yy")=A1&TEXT(B1, "mmm-yy")))-1)/5)+1
I've set this to repeat after 5 for an example. I'll leave it to you to change the modifier to 50. Fill down as necessary.

Resources