I have a dynamic hyperlink that selects the last cell in a specified column within a sheet, regardless of th number of items in that column. So if I have 22 items in a column, the link will select the 23rd row, etc.
What I am trying to do is have it select the last cell (in the same fashion), but within a different sheet of the same workbook - provided that my reference cell is set to the appropriate number (i.e. I have a dropdown selector which sets the value of this reference cell and that changes the hyperlink.
I implemented this using an IF and a COUNTA statement, but I can't figure out how to make the link formula count the number of items in columns of different sheets. Here's the function:
=IF(J6=1, HYPERLINK("#Parts!b"&COUNTA(B:B)+3, "Add New Entry"), HYPERLINK("#Employees!b"&COUNTA(B:B)+3, "Add New Entry"))
How do I change the formula so that the COUNTA is executed in the appropriate worksheet?
Just add your sheet name! in front of the column range you've defined in counta(). For instance if your sheet's name is sheet1 you would do the following:
=IF(J6=1, HYPERLINK("#Parts!b"&COUNTA(sheet1!B:B)+3, "Add New Entry"), HYPERLINK("#Employees!b"&COUNTA(sheet1!B:B)+3, "Add New Entry"))
Related
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.
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.
I have an Excel spreadsheet where on Sheet 1 the Department Id is represented as a number and where on Sheet 2 there is a list of those numbers with the Department Name next to them.
If possible I would like some help and advice as I want to allow the user to select the Department Name from a drop down list and have it populate a hidden field with the department number.
Something like in Sheet 3 with the Department Id being stored for example in the C column on that page:
Sheet 1
Sheet 2
Sheet 3
This could be one approach.
If I have understood you correctly, the user will select the department name in a drop-down list in Sheet 3 and and the index number associated with that department name will appear. The user will not be limited to what name (andy, bob) it is in the adjacent column...
Result will be (notice this is a Excel Table!) :
We have the 3 sheets:
Select the data areas and click on "Format as Table", Select the option "My data has headers". Do this for all the 3 sheets.
Name your tables: "Design" -> "Table Name". I will use "Table1" for "Sheet1", "Table2" for "Sheet2" etc. It will make life easier when you link and refer in formulas. Notice that for "Sheet3" I also add a dummy column C. I name it "Index Number".
Go to "Sheet2" and select the range that you want to use as your drop-down list (in my case i choose Department Names and selected "B2:B8". Click "Formulas" -> "Name Manager" -> "New..."
This window will pop-up. Name it an easy name (I named it: "Department_Names") and check that the "Refers to:" is in this format "=TableX[Column Name]". In our case =Table2[Department]. Notice that the name manager don't use "B2:B8", rather is reference to the table column area. The last step is very important!
Go to Sheet3. Click on cell where you want to apply the drop-down list (I use B2 in the example). Click "Data" -> "Data Validation".
Data Validation window will now pop-up. Go to "List" and in the field "Source:" you write your named range as =Department_Names (the one I named "Department_Names"). The drop-down list will use the values in the range that "Department_Names" are applied to. In our case it will make a drop-down list of all the department names from "Sheet2", range B2:B8.
Go to "Sheet3" and enter the formula below in the cell C2 as shown in the picture.
Notice I use " ; "as delimiter (European version of Excel, US user will probably use" , ").
=IF([#Department]="","",IFERROR(INDEX(Table2[ID],MATCH([#Department],Table2[Department],0)),))
The first part creates our Index number:
...IFERROR(INDEX(Table2[ID],MATCH([#Department],Table2[Department],0)),)
Return the Index number from "Table2", Column ID. INDEX(Table2[ID]
lookup value in the MATCH formula comes from "Table3", Department
(drop-down list)
The lookup value will look in "Table2", column Department.
Will take care of 0 that will be created when nothing is selected in the "Table3", Department column (see next picture for example)
=IF([#Department]="","", ...formula...)
Formula without the =IF([#Department]="","", ...formula...)
You can hide the "Index Number" column in "Sheet3" if you don't want to have it visible.
Right click on the Column C header and choose "Hide".
Only for demonstration purpose here. I create a dummy column "Only for show hidden column values". So when the user selects a Department name, it will change the index number associated to that department.
So why the use of tables and named range?
Let's say you need to add a new department. We add a department in the "Table2" and we give it ID: 7 and Department Name: Department H.
What happens in your "Sheet3" is that the drop-down list will automatically catch the new row. The range named to "Department_Names" will adjust to the table rows because it's linked to "Table2[Department]". This is also true if you decrease rows for Table2. Source
I have not tested it, but I'm quite sure that you can link a table to an external source. So when you import your data to the table (given the headers is static) the table will be updated with "Refresh All" button in Excel. Something to explore and look further into :)
It can be done with INDEX/MATCH.
As an example:
Sheet1 contains your lookup table.
For simplicity sake Sheet1 has numbers 1 - 6 in the range A1:A6 and A - F in the range B1:B6.
1 - 6 are the primary keys and A - F are the descriptions.
Sheet2 has Data Validation in column A: Allow List using =Sheet1!$B$1:$B$6 as the Source. This will give you the drop-down in column A.
In column B, which is hidden, you have the formula =IFERROR(INDEX(Sheet1!$A:$A,MATCH($A2,Sheet1!$B:$B,0)),"")
The MATCH formula will return the row number in Sheet1 that the description appears in.
The INDEX formula will return a reference to the cell in column A on that same row - giving the Primary Key value.
If no match is found then #N/A is returned which is dealt with by the IFERROR statement.
This method will work if your departments are less than equal to 32.
In UTF 8 characters from code 128 to 160 are hidden (among many others). You can use these characters as your id key, you have to just concatenate them with your department name.
This is a screenshot of excel
3rd column is the Unicode character, 4th is concatenation of this character and the department name and last column is extracted id from the new department name.
These are the formulas
At the end it can also work if your departments are more than 32 but you have to find another slot of non-printable characters
You have to use the new department names as data validation drop downs where department entry is required and can extract the id from the entered department
Lets say
sheet3.name = "d"
Is there a way I could put in a cell on sheet2 the formula =sum(sheet3!b:b) where sheet3 is being substituted with the actual sheet3 name?
I can only get =sum('d'!b:b) to work so far.
I could use VBA for this probably but I'm curious how to do this in a cell so I don't have to run a macro each time.
If you can use a UDF User Defined Function that will return the sheet name
Function SHEETNAME(number As Long) As String
SHEETNAME = Sheets(number).Name
End Function
then a formula like
=SUM(INDIRECT(SHEETNAME(3) &"!B:B"))
will return the sum from column B on sheet 3.
SHEETNAME(number) returns the sheet name of the number which is index.
So Sheet(1) returns Sheet1, etc
Use below formula anywhere in the sheet to get the sheet name - the sheet must have a filename for this to work:
=REPLACE(CELL("filename"),1,FIND("]",CELL("filename")),"")
You can either reference that cell using Indirect:
=SUM(Indirect("'"&A1&"'!B:B"))
or, if you don't want to have a second cell, you can combine the two formulas into one:
=SUM(INDIRECT("'"&REPLACE(CELL("filename"),1,FIND("]",CELL("filename")),"")&"'!B:B"))
For anyone not concerned with the order of the sheets, the post by Biff here on mrexcel.com works well.
In Excel 2013, go to the Formulas tab in the ribbon and make a defined name:
Name: SheetNames
Refers to: =GET.WORKBOOK(1)&T(NOW())
Then use a formula like this example:
=INDIRECT("'"&INDEX(MID(SheetNames,FIND("]",SheetNames)+1,255),A3)&"'!A1")
where A3 refers to the index number in a cell in the current sheet, and A1 refers to the location of the value to be retrieved from the other sheet. I.e., in the current sheet, if A3 = 2, then the formula will point to cell A1 in the second sheet of the workbook. I just use a column of index numbers in my current sheet, then drag this formula down and it fills in values from all of my other sheets.
You will need to save as a macro-enabled file (.xlsm).
I'm not sure if this is a good idea but it's the first one I could think of.
I would add additional function to your VBA project which will return actual name of your Sheet3:
Function Sheet3Name()
Sheet3Name = Sheet3.Name
End Function
Next, when you create sum formula of column B:B in Excel cell you need to do it in this way:
=SUM(INDIRECT(Sheet3Name()&"!A:A"))
I have an Excel with 2 worksheets, first will be dinamically filled with data, having a row with a combo box feeding from row A on the second worksheet.
The second worksheet will also be filled dinamically, where will be:
Row A:
some values of variable number
B1 - Number of values on Row A to considerate.
My question is - Im using Data Validation > List to define the values on the ws1rowA combo box, is it possible to range from A1 to A(value in B1) ?
So far tried this on Data Validation "source" field:
=Sheet2!$A$1:offset(Sheet2!$A$1,=Sheet2!$B$1,0,1,1)
but an error is returned
You can also use INDIRECT function for this.
=INDIRECT("Sheet2!$A$1:$A"&Sheet2!$B$1)
In my version of Excel "You cannot use references to other worksheets or workbooks for Data Validation criteria" but you can use named ranges that have a Workbook Scope, so name a range (eg DataValid) to apply to say the range as #Maxim Korneev and then for Data Validation in Sheet1 use a list whose Source: is =DataValid.
Sure, just use
=OFFSET(Sheet2!$A$1,0,0,Sheet2!$B$1,1)