Index/Match returning wrong value - excel

Summary tab:
Source tab:
I'm having some trouble using index match combo and getting the data to reference correctly.
what I am trying to achieve is in a tab called "Summary" I have a calendar with range D5:O6. the first cell in the calendar should change everyday to reflect the current date which will change the rest of the row making a rolling calendar. I have a data reference sheet called "PFS" from which the data needs to be referenced.
The thing I'm having trouble with is that with the formula
=INDEX(PFS, MATCH(A8,Snames,0),MATCH(D5,Sdates,0))
is returning the top left intersection (B8 of the source tab) of A8 and D5 values smith, bob & 4-Aug. a cell that i have entered the value "Wrong Corner".
Snames A8:A9, Sdates D5:O5 are the rows and columns containing the dates and names from the Summary tab
what I need help with is why its returning the wrong intersection and what I can do different to get the data I'm looking for.
The correct return would be the number one, which I have conditionally formatted to turn the cell blue and blank the text

You don't show what PFS references to. It seems to start in A1.
You can either use a range that starts in the correct cell, or add the required offset to the Match results.
=INDEX(PFS, MATCH(A8,Snames,0)+2,MATCH(D5,Sdates,0)+2)
Also make sure that Sname and Sdates refer to the ranges in the Source tab, not the Summary tab.

Related

How to create a filtered drop down list based on multiple criteria

on the below Schedule image I am trying to create a Drop Down List in the "Gland (A)" Column. Rather than just creating a list of all available "Glands" I want that list to be filtered based on the data within "CORES / PAIRS", "SIZE mm" and "CABLE TYPE". For this example we will use a "3c 16 BS5467, XLPE/SWA/PVC".
Schedule
To determine the filter for the list, the "ID Ø (mm)" and "OD Ø (mm)" for the select cable need to be taken in to consideration, see Cables image below. As you can see for the example we are using the cable has an "ID" of 15.5 and "OD" of 20.35.
Cables
Finally seen below in the Glands image, the "ID" from above needs to be within the "INNER MIN/MAX" and the "OD" needs to be within the "OUTER MIN/MAX".
Glands
So back to the first image in the "GLAND (A)" columns for row 4 the drop down list should be filtered and only show concatenated values:
151/RAC/B/M25
501/453/UNIV/B/M25
ICG/653/UNIV/B/M25
In two separate formulas I managed to VLOOKUP just the "OD" based on the cable types:
=VLOOKUP(B4&C4&E4,'Cables'!A$2:H$169,8,FALSE)
Then based on the retrieved value LOOKUP the "GLAND SIZE" from within the "OUTER MIN/MAX":
=LOOKUP(2,1/((F4>='Glands'!E$3:E$9 + 1)*(F4<='Glands'!F$3:F$9 - 1)),'Glands'!B$3:B$9)
The problem is I don't know how to include checking the "ID" as well, also to retrieve concatenated cells ("GLAND TYPE" and "GLAND SIZE") and then for them to be a Data Validation Drop Down List.
Any help with this would be greatly appreciated.
Thank you
Ok, this is going to be hard to explain. I'll do my best. Maybe if we wrap this up in a dedicated sheet we won't make mistakes.
PHASE 1: create a new sheet.
Create a new sheet and name it "Calculations". We will put most of the stuff here. First of all we type "Selected row in Schedule" in the cell A1.
PHASE 2: determine what cable number is selected.
Since we have multiple entry of cable in the Schedule sheet, we will need multiple list of possible glades. Creating a dedicated list for each lane or costraining the user freedom would be unpractical. Therefore we need to know what row the user is selecting in the Schedule sheet. We have to use VBA. Right-click on the Schedule sheet name tag and click on "View code". Copy-paste this code in the window that has appeared:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Filling the cell A2 in the sheet Calculation with the row number of the selected _
cell in the scheet Schedule.
Sheets("Calculations").Range("A2").Value = ActiveCell.Row
'Preventing multiple selection in the F column of the sheet Schedule.
If Not Application.Intersect(Target, Range("F:F")) Is Nothing Then
Target.Resize(1, 1).Select
End If
End Sub
This code will report in the cell A2 of the sheet Calculation the row number actually selected in the sheet Schedule. Everytime the selection is changed, the value changes. It also prevent the selection of multiple rows of the F column in Schedule sheet (the column where Glades dropdown list will be placed). You can test the code by changing the selection in the Schedule sheet and looking at the result in Calculations sheet.
PHASE 3: determine what type of cable is selected and its ID/OD.
In the Calculation sheet, type "Selected cable" in range B1. In range B2 type this formula:
=INDEX(Schedule!$A:$F,Calculations!$A$2,2)&INDEX(Schedule!$A:$F,Calculations!$A$2,3)&INDEX(Schedule!$A:$F,Calculations!$A$2,5)
This formula reconstruct the name we will search in the LOOKUP column of the Cables sheet. It's a series of INDEX functions, nothing really complicated.
Now that we know what to look for, we can extract its ID/OD. Type "ID" in the cell C1 and "OD" in cell D1. In cell C2 type this formula:
=VLOOKUP($B$2,Cables!$A:$H,7,FALSE)
In cell D2 type this formula:
=VLOOKUP($B$2,Cables!$A:$H,8,FALSE)
These formulas will search the cables' list in the Cables sheet and extract the ID/OD of the given one.
PHASE 4: create the filtered list.
Your glands' list has its first gland in the third row. So just to make it easier to crosscheck the data, we will place our formulas accordingly. In sheet Calculations type "List stage 1" in cell E2. In cell E3 type this formula:
=IF(AND(C$2>=Glands!C3,C$2<=Glands!D3,D$2>=Glands!E3,D$2<=Glands!F3),ROW(),"")
Drag it all the way down until it will be cover the same number of rows of the glands' list in the Gland sheet. This formula will "highlight" in what rows are the glands we are looking for (if there are any). At this point the list is very long, unsorted and presumably has a lot of blank cells. We need to sort it. In cell F2 type "List stage 2". In cell F3 type this formula:
=IF.ERROR(SMALL(E:E,ROW()-ROW(F$2)),"")
Drag this one down just like the previous one. Now we have a compact list of numbers. We need to translate them into glade's names. In cell G2 type "Filtered gland list". In cell G3 type this formula:
=IF.ERRORE(INDEX(Glands!A:B,F3,1)&"/"&INDEX(Glands!A:B,F3,2),"")
Drag it down again like previously did. We have our list.
PHASE 5: name the list.
We need to create a dynamic reference to the list to cut out all the blank cells. Define a new name calling it Gland_Filtered_List referred to this formula:
=INDIRECT("Calculations!$G$3:G" & ROWS(Calculations!$G$3:$G$1048576) -COUNT.BLANK(Calculations!$G$3:$G$1048576)+2)
PHASE 6: insert data validation.
In the Schedule sheet, create a data validation for the glands column using the list mode and Gland_Filtered_List as origin.
That should do the trick. Right now i have to hurry for work, so i can't check the explanation. Everything should be in order. Try this and ask any question. I'll answer later.

Is there a Excel Formula for auto filling a price when certain option of choices is picked?

I am working in Excel. I am trying to come up with a formula that is linked to a drop down menu of choices. I have attached an image below that shows a 'Status' column and 'Double Handling' column. My end goal is when you click a status option the corresponding price gets autofilled in the double handling column.
For example Status :Price
Unchecked :$400,
Checked :$600,
Laydown :$200,
in SWO :$200,
Progress :$200,
Paint :$200,
Laydown :$200,
Site :$200,
If you have your Drop Down options on another tab (a Lookup Sheet), then you can put the Price next to them, and use a VLOOKUP
=VLOOKUP(A1,LookupSheet!$A:$B, 2, FALSE)
This also lets you use a Named Range in your Drop-Downs, so that you just have to add or remove items to the Lookup Sheet, and it will automatically update all of your options. The Named Range would need to contain a Function that used INDEX to set the range, like this:
=LookupSheet!$A$1:INDEX(LookupSheet!$A:$A, MAX(COUNTA(LookupSheet!$A:$A), 1))
(If your Lookup Sheet includes a Header Row, then you will probably want to change $A$1 to $A$2, and that final , 1)) to , 2)) instead)
If you don't want to use a Lookup Sheet, you can include the Lookup Table in the function as an array:
=VLOOKUP(A1, {"Unchecked",400;"Checked",600;"Laydown",200;"in SWO",200;"Progress",200;"Paint",200;"Laydown",200;"Site",200}, 2, FALSE)
The whole array goes inside braces (curly brackets, {}), values on the same Row are separated with Commas ({Input,Output}), and Rows are separated with Semicolons ({Input1,Output1;Input2,Output2})
Though it may seem a bit lenghty, if for whatever reason you want to change up amount, I believe you could nicely implement CHOOSE here:
=CHOOSE(MATCH(A1,{"Unchecked Drawing","Checked Drawing","in SWO","Progress Assign LamSar Shop","Progress Assign Subcontractor","Paint","Laydown","Site"},0),400,600,200,200,200,200,200,200)
Range A1 in my formula refers to the cell with the drop-down. Also, when empty, there will be an error (since MATCH cannot find a match). You could counter that with wrapping the formula in an IFERROR(.....,"").

Excel input field that pulls data from range

I'm trying to create an input/search field in an excel sheet that when someone enters data in the field, it starts autopopulating from X Range, when they find the data they want they hit enter and it pulls from Y Range.
Closest I've found is XLOOKUP, but I can't get it to work on a field when someone types into that field. I want this to work through column A of the entire sheet, so when the user goes to a new line it does the same as the line above.
So, input data into A4, while typing it search C:C and auto fills in as I type. Once I find what I like I hit enter and it pulls the cell next to the C cell I found the data on, resulting cell data, so D:D column.
I've tried inputing this into a dropdown validate field, but no go, just errors out:
=XLOOKUP(INDIRECT("a9"), C:C, D:D)

How to Extract, Change and Replace Data?

Maybe I have used the wrong phrase to search but I have not been able to find a solution to the following challenge for Excel/VBA:
In Sheet 1 I have a database of order data from cells A1 to F10. Each row contains data for one order. Column A contains the order number.
As first step I, in sheet 2, wish to make a search on the order number and retrieve all data for that order into cells A5 to F5 in sheet 2.
After reviewing the data (and running another macro to recalculate the sales price) I wish to have the revised data replace the original data in sheet 1.
Can anyone help me with this?
Thank you in advance!
The 1st part does not need macro.
vlookup (fkeres magyarul) is your function. If you put this function in A5-F5 fields in sheet 2, looking for a given order number, in Sheet1 $A$1:$F$10, entering the required column number, asking exact match (FALSE), it works nicely. I entered the functions parameters in my previous sentence.
The 2nd part needs macro which makes Copy Paste back.
OR
Look for the requested order row in sheet2 A5 cell with MATCH (HOL.VAN magyarul) function, like =MATCH(A1;Sheet1!A1:A10;0)
and put INDIRECT (INDIREKT magyarul) function, like =INDIRECT("Sheet1!B"&A5;TRUE) in B5, etc.
In this case the Copy-Paste back macro is (starting from Sheet2):
Myorder = Range("A5").Value
Range("B5:F5").Select ' A5 is the row number of order, not the order No
Selection.Copy
Application.Goto Reference:=Worksheets("Munka1").Range("A" & Myorder)
ActiveSheet.Paste
...or very similar

Excel charts - setting series end dynamically

I've got a spreadsheet with plenty of graphs in it and one sheet with loads of data feeding those graphs.
I've plotted the data on each graph using
=Sheet1!$C5:$C$3000
This basically just plots the values in C5 to C3000 on a graph.
Regularly though I just want to look at a subset of the data i.e. I might just want to look at the first 1000 rows for example. Currently to do this I have to modify the formula in each of my graphs which takes time.
Would you know a way to simplify this? Ideally if I could just have a cell on single sheet that it reads in the row number from and plots all the graphs from C5 to C 'row number' would be best.
Any help would be much appreciated.
OK, I had to do a little more research, here's how to make it work,
completely within the spreadsheet (without VBA):
Using A1 as the end of your desired range,
and the chart being on the same sheet as the data:
Name the first cell of the data (C5) as a named range, say TESTRANGE.
Created a named range MYDATA as the following formula:
=OFFSET(TESTRANGE, 0, 0, Sheet1!$A$1, 1)
Now, go to the SERIES tab of the chart SOURCE DATA dialog,
and change your VALUES statement to:
=Sheet1!MYDATA
Now everytime you change the A1 cell value, it'll change the chart.
Thanks to Robert Mearns for catching the flaws in my previous answer.
This can be achieved in two steps:
Create a dynamic named range
Add some VBA code to update the charts data source to the named range
Create a dynamic named Range
Enter the number of rows in your data range into a cell on your data sheet.
Create a named range on your data sheet (Insert - Name - Define) called MyRange that has a formula similar this:
=OFFSET(Sheet1!$A$1,0,0,Sheet1!$D$1,3)
Update the formula to match your layout
Sheet1!$A$1 set this to the top left hand side of your data range
Sheet1!$D$1 set this to the cell containing the number of rows
3 set this value to the number of columns
Test that the named range is working:
Select the dropdown menus Edit - Go To, type MyRange into the reference field.
Your data area for the chart should be selected.
Add some VBA code
Open the VBA IDE (Alt-F11)
Select Sheet1 in the VBAProject window and insert this code
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> "$D$1" Then Exit Sub
'Change $D$1 to the cell where you have entered the number of rows
'When the sheet changes, code checks to see if the cell $D$1 has changed
ThisWorkbook.Sheets("Sheet1").ChartObjects(1).Chart.SetSourceData _
Source:=ThisWorkbook.Sheets("Sheet1").Range("MyRange")
' ThisWorkbook.Sheets("Chart1").SetSourceData _
Source:=ThisWorkbook.Sheets("Sheet1").Range("MyRange")
'The first line of code assumes that chart is embedded into Sheet1
'The second line assumes that the chart is in its own chart sheet
'Uncomment and change as required
'Add more code here to update all the other charts
End Sub
Things to watch for
Do not directly use the named range as the data source for the chart. If you enter the named range "MyRange" as the Source Data - Data Range for the chart, Excel will automatically convert the named range into an actual range. Any future changes to your named range will therefore not update your chart.
Performance might be impacted by the approaches listed above.
The OFFSET function in the named range is "volatile" which means that it recalculates whenever any cell in the workbook calculates. If performance is an issue, replace it with the INDEX formula.
=Sheet1!$A$1:INDEX(Sheet1!$1:$65536,Sheet1!$D$1,2)
The code fires everytime data is changed on Sheet1. If performance is an issue, change the code to run only when requested (i.e. via a button or menu).
You could look at dynamic ranges. If you use the OFFSET function, you can specify a starting cell and the number of rows and columns to select. This site has some useful information about assigning a name to an OFFSET range.
You can set the range for a chart dynamically in Excel. You can use something like the following VBA code to do it:
Private Sub Worksheet_Change(ByVal Target as Range)
Select Case Target
Case Cells(14, 2)
Sheet1.ChartObjects(1).Chart.SetSourceData Range("$C5:$C$" & Cells(14,2))
...
End Select
End Sub
In this case, the cell containing the number of the last row to include is B14 (remember row first when referring to the Cells object). You could also use a variable instead of the Cells reference if you wanted to do this entirely in code. (This works in both 2007 and 2003.) You can assign this procedure to a button and click it to refresh your chart once you update the cell containing the last row.
However, this may not be precisely what you want to do ... I am not aware of a way to use a formula directly within a chart to specify source data.
Edit: And as PConroy points out in a comment, you could put this code in the Change event for that worksheet, so that neither a button nor a key combination is necessary to run the code. You can also add code so that it updates each chart only when the matching cell is edited.
I've updated the example above to reflect this.
+1s for the name solution.
Note that names don't really really reference ranges, they reference formulae. That's why you can set a name to something like "=OFFSET(...)" or "=COUNT(...)". You can create named constants, just make the name reference something like "=42".
Named formulae and array formulae are the two worksheet techniques that I find myself applying to not-quite-power-user worksheets over and over again.
An easy way to do this is to just hide the rows/columns you don't want included - when you go to the graph it automatically excludes the hidden rows/columns
Enhancing the answer of #Robert Mearns, here's how to use dynamic cells ranges for graphs using only the Excel's formulas (no VBA required):
Create a dynamic named Range
Say you have 3 columns like:
A5 | Time | Data1 | Data2 |
A6 | 00:00 | 123123 | 234234 |
...
A3000 | 16:54 | 678678 | 987987 |
Now, the range of your data may change according to the data you may have, like you have 20 rows of data, 3000 rows of data or even 25000 rows of data. You want to have a graph that will be updated automatically without the need to re-set the range of your data every time you update the data itself.
Here's how to do it simply:
Define another cell that it's value will have the number of the occupied cells with data, and put the formula =COUNTIF(A:A,"<>"&"") in it. For example, this will be in cell D1.
Go to "Formulas" tab -> "Define Name" to define a name range.
In the "New Name" window:
i. Give your data range a name, like DataRange for example.
ii. In the "Refers to" set the formula to: =OFFSET(Sheet1!$A$1, 0, 0,Sheet1!$D$1,3),
where:
Sheet1!$A$1 => Reference: is the Reference from which you want to base the offset.
0 => Rows: is the number of rows, up or down, that you want the upper-left cell of the results to refer to.
0 => Columns: is the number of columns, to the left or right, that you want the upper-left cell of the results to refer to.
Sheet1!$D$1 => Height: is the height, in number of rows, that you want the result to be.
3 => Width: is the width, in number of columns, that you want the result to be.
Add a Graph, and in the "Select Data Source" window, in the Chart data range, insert the formula as you created. For the example: =Sheet1!DataRange
The Cons: If you directly use the named range as the data source for the chart, Excel will automatically convert the named range into an actual range. Any future changes to your named range will therefore not update your chart.
For that you need to edit the chart and re-set the range to =Sheet1!DataRange every time. This may not be so usable, but it's better than editing the range manually...

Resources