Excel Inputbox Function with conditions - excel

Background info:
Column A = Last Names,
Column B = First Names,
Column C = a drop down box with a list of options determining whether
the person listed in A1B1 has a certain status(active rep,
disaffiliated, etc) there are 5 or 6
In column D, I would like an input box to prompt the user depending on what the answer choice is in Column C. If for example 'C2' = "Active Rep", I'd like the prompt to ask for a date mmddyy, or if they hit cancel to allow them to enter something manually (text)
If 'C2' = Disaffiliated, I would like to to provide a drop down box giving them a list of options from the control page.
This would need to happen for each named person in Column A for which there are about 100
Is this possible or am I thinking too big and just need to simplify things.

You can use the WorkSheet_Change() event to check what was input and do a Select Case statement to handle each selection differently.

Related

How can I make a drop down list that stores an index value in a hidden field?

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

How do I add a simple multiplication formula to excel user input box?

I have a question which I believe requires a bit of coding but I could be wrong.
I am trying to create a pdf catalog using excel and publisher together. Publisher uses the data in excel spreadsheet to automatically create a catalog.
I would like to create a user input box for clients to type a quantity (with a default value of "0").
I would like to add a formula to my user input box so that whatever number the client enters as quantity, it will multiply that value by the price in cell "C1".
I would like the default to be 0 in the input box.
If the user inputs (e.g. 5) then I would like to multiply that value by C1 (e.g. $2.99) and then display the result in a separate cell (e.g. E1)
If there is an easier way to incorporate quantity x price using excel and user input for quantity please let me know.
Than
You could use a simple UserForm with a TextBox and Label with code as below
updated for your new comment to dump to e1
Code uses cells on first worksheet.
Private Sub TextBox1_Change()
Me.Label1 = CLng(Me.TextBox1) * Sheets(1).[c1].Value
Sheets(1).[e1].Value = Me.Label1
End Sub
[
You enter the formula in the result cell. The price cell is set by you and should not be editable by the user. The quantity cell should be edited by the user.
The result cell would have a formula like '=A1*B1'. Really trivial actually.

Excel filter Multiple Value in One Cell

I am looking for help on filtering multiple values in one cell delimited by a comma.
For example I have a spreadsheet with the following data:
Column A (Risk) Column B (Risk Mitigation)
Risk A Requirement1, Requirement2
Risk B Requirement2, Requirement6, Requirement7
Risk C Requirement1, Requirement3, Requirement9
When I filter on the 'Requirement Mitigation' Column I would like to see check boxes for the following:
Requirement1
Requirement2
Requirement3
Requirement4
Requirement5
...
Requirement9
So for my example when I only check the Requirement 1 filter box, only 'Risk A' and 'Risk C' rows would be displayed
Currently when I filter it does by the unique cell value, which gives me
Requirement1, Requirement2
Requirement2, Requirement6, Requirement7
Requirement1, Requirement3, Requirement9
Please note that above is just an example and I have thousand of individual requirements, so it would not be as simple as having one column per requirement.
I open to any suggestions including creating vbscripts.
Any help would be greatly appreciated.
This will be tricky.
First you'll need to create a form that will contain a list box and populate that list box with the Requirements you have in their correct syntax.
Then you'll need to create a loop that will go through every cell in a column and save each of them to a string, you could make a one dimensional string array to save them all in that as well.
Then you'll need a loop that will go through each string and use the split function to seperate the strings with a delimeter, you'll need to set your delimiter to ", " to ensure it seperates the strings at the commas.
Then you'll need a loop that will run after you've made your selection from the listbox in your form. this loop will go through every string in your 2D array and check if it contains any of the requirements in your listbox. If it is not, run the code: Range("B" & x).EntireRow.Hidden = True where x is the row, you can use one of the variables in your loop for this.
If you need more specific information that this I may need to see what you've already done, it is possible as well to use this method to automatically populate the list box in your form.

Excel spread sheet if statement

I'm working on an excel spreadsheet and want an if statement in a cell that allows user input if a certain condition is met, and calculates a value otherwise. Something like
=if(condition true, whatever user wants, 5*$A$1,)
Is there a way to do this?
You won't be able to have the user-input in the same cell as your formula. (without using VBA)
To do it without VBA you will need to use at least 2 cells, one with your formula, and one for the user value
There are a couple of ways you can do it with VBA
Heres a simple one, but would not really recomment it, if lots of cells use this it you'll get lots of inputboxes!
usage: =IF(condition, UserInput(), false result)
Public Function UserInput() As Integer ' used integer as an example
Dim Result As Variant
Result = Application.InputBox("Enter an Integer", "Input Required", , , , , , 1) ' inputbox, the final 1 makes it only accept numbers
If VarType(Result) = vbBoolean Then
UserInput = 0 ' the default value
Else
UserInput = CInt(Result) ' make sure its an integer
End If
End Function
Another one, would involve using the selection change and cell change events to read the initial value of the cell being changed, and allow the change (adding the value into the initial formula's "true" block or deny the changes by reverting the cells formula to the initial one.
You either need to use a Macro to update only null columns or you need to allow user to enter values in another column and then merge the values in this column, third option is to fill it with formulas and allow people to edit it to any value if they want only values
=IF(C11="Economic",120,IF(C11="DBServer",480,IF(C11="Gamer",120,IF(C11="Custom",M15,"null"))))
My example was to build an optimal computer given certain constraints. There was a drop down with Economic, DBServer, Gamer, and Custom as options. If you chose economic, then 120 would show up in the cell, DbServer meant 480, etc. If you selected custom, then it would refer to cell M15 which was a user input that didn't affect the code of the cell you wanted the final number in.

Filter cells in excel based on true value and not on formatted value

I have this spreadsheet where in column A I have multiple categorical values, for sake of simplicity let's say it looks something like A/A/A/B/B/C/C/C/C.
Now, I would like to insert a line for the total after each group. Column A should end up looking something like this A/A/A/A TOTAL/B/B/B TOTAL/C/C/C/C/C TOTAL. Got this?
Problem is when I filter for, say, C values the "C TOTAL" does not show up together with the others. Now that seems right as the value "C TOTAL" is not the same as "C".
So I figured I could write "C" instead of "C TOTAL" and then apply a format like # " TOTAL".
Now the value in the cell is the same as the others (i.e. "C") but it shows as if it was "C TOTAL".
I thought this would work, but still when I filter I see both "C" and "C TOTAL" listed.
Why does excel separate them if the value is the same? How can I do so that filtering only accounts for the true value in the cells and not their format too?
Thank you guys for your help!
Well I have a solution to your overall goal (not this specific problem, but it makes this problem unnecessary)
If you have a range (and NOT what I call a "Big-T Table" (Big-T Tables get the "Table Tools" context ribbon group to appear when selected)) then this solution could work for your goal of a total for each category.
Click in your data range -> Data Tab -> Subtotal (in outline group) -> select "at each change in" (probably your category) -> select your function of choice from dropdown -> Choose which columns to subtotal with checkboxes - > choose your other options -> done!
Here is example dialog box

Resources