Alerting for incorrect cell values - excel

My problem: I have two ranges R16 and R01. These ranges were set up by swiping each range and then renaming them in the upper left panel of the sheet. Each range requires users to fill in each cell with a value. R16 requires users to enter a number of 0 through 5. The range R01 requires a value of 0 or 1 to be entered. NO cell can be left blank in any cell within these two ranges. These ranges and requirements are specific to this sheet only. It would be nice if at the time of user entering a number, an error message appeared like [invalid entry] if the value inputted was outside parameters set. For example, in R16, if someone entered 12 or -1 they would be alerted. Finally when the user presses a button on the page to use these values in a separate process, it is essential to check that no cell is left blank. I am trying to find a way to halt the running of the marco (via the button) if these parameters above are not met. Thank you

You don't need programming for the first part, this is a built-in feature in Excel called "Validation". The second part of your question, the pressing of the button, requires a macro that checks both cells.

Related

Excel data validation by typing instead of selection

I am struggling with the autocomplete list in my excel document.
I was trying to use the example from OzGrid
https://www.ozgrid.com/Excel/autocomplete-validation.htm
But it seems like this step is not explained well enough.
First of all, I did step one by linking my cells between these 2 sheets.
[![enter image description here][1]][1]
In both "Frontsheet" and "Locality" the list range is from C51 to C67, as per the OzGrid advice.
Next the step with [Dynamic Ranges][2] probably refers to older versions of Excel with traditional menu, where we could select the "Tools" from the bar. Now in Excel 2016 I believe, that it should be like follows:
Formulas - Name manager - New... where we put our name, scope and refers to (range). I have created the Myrange
[![enter image description here][3]][3]
and finally, I put the formula (assuming that the C50 is my dropdown list cell):
=OFFSET(Frontsheet!$C$50,0,0,MATCH("*",Frontsheet!$C$51:$C$67,-1),1)
but I am getting nothing apart of #N/A
I don't know what's next.
I don't want to use VBA this time, because I want to have these lists allocated to the specified cells. I want to search the records by typing not by selecting since I have got them quite a lot. Is it possible?
This question is somewhat a duplicate to the previous ones, which unfortunately didn't bring me the solution.
Excel 2010: how to use autocomplete in validation list
Excel data validation with suggestions/autocomplete
Your formula =OFFSET(Frontsheet!$C$50,0,0,MATCH("*",Frontsheet!$C$51:$C$67,-1),1) shouldn't return anything but #N/A when entered in a cell because it defiens a range which Excel can't display in a single cell. However, you can use it to define a named range and then use that name to define a Data Validation list.
MATCH("*",Frontsheet!$C$51:$C$67,-1) doesn't work reliably if there are numbers in the lookup range. You might replace it with COUNTA(Frontsheet!$C$51:$C$67) which can deal with numbers or text equally well. The difference is that MATCH will produce the entire list, including intervening blanks, while COUNTA will truncate the list at the bottom by as many rows as there are blanks higher up. Either way, one usually avoids blanks in the source for a validation list.
If you want the user to be able to either choose or enter, you must disable Show alert after invalid data is entered on the Error Alert tab of the Data Validation dialog box, where you set up the validation rules.
The OzGrid solution is poorly written and deceptive. It is simply capitalizing on AutoComplete for cell values. There is no magic in linking to another sheet and using offset or in creating a named reference.
All you need to do is add a list of values you intend to use in the column above the column. Avoid empty rows between this list of 'default' values and what you intend to enter.
Skipped rows 'break' AutoComplete for cells.
But can be resolved by adding an adjacent contiguous 'indexing' column.

How to Sum value from current cell plus input cell

I have two problems:
How to make a cell input? I need to enter a number and after pressing "enter" delete the number so I can add more input.
How to SUM the entered input with the value of another cell, for example C3 and store the result on C3?
I don't know how to delete the cell after pressing enter.
I've tried writing at C3 "=SUM(C3+F3)" and "=0+SUM(C3+F3)" both gave me a #REF ERROR.
Case:
I want to know how much money I have spent in one day. So C3 cell at the beginning have a 0 and F3 cell (input) is empty.
The point is if I buy a $3 souvenir, write 3 at F3, press enter (delete the 3 to make F3 empty) and make a SUM with whatever was at C3 plus that $3.
I would create a button, then it is clearer what you want to happen, though you could hook into the key press.
Go to File Options Customise and customise the ribbon to add the Developer tool bar.
on the Insert command, add a new button to the form. It will ask which macro you want, click New
Past this code:
Sub Button1_Click()
Range("F3").Value = Range("F3").Value + Range("C3").Value
Range("C3").Value = ""
End Sub
into the button click, and then when you click the button it will take the value in C3 and add it to F3 and then clear the value in C3.
Remember to save the workbook as MACRO ENABLE WORKBOOK, else the macros won't save.
click button
Hope that helps
Overwriting the same cell with different values and then expecting a sum of the previously entered values is not a good approach. If you want to understand why the result is a specific value, you need to be able to see which values contributed in which way to that result.
The better approach is to list all different numbers in one column and then calculate a running total in another column. Just like a bank statement. A bank statement shows you the current balance, but also each transaction, debit or credit, that went into calculating that balance. If you did not see the transactions, you don't really know if your pay check has already been included in the balance or not.
If you overwrite the same cell multiple times, how do you know if you have made a mistake and entered the cost for lunch twice, or made a typo in the numbers?
So, enter the data in rows. Each data point in a new row. Maybe use a column for date, one for money spent. Then use simple formulas in other columns to calculate what you want to calculate. You won't need any VBA or script or buttons for that.

Allow Form Controls to affect a Locked Cell

I am working on an excel spread sheet that has form controls in place so that only the numbers 0 through 4 can be entered into a cell. These form controls are two arrows, one pointing up to increase the value and one pointing down to decrease the value. The affected cell is set to 0 by default and have the minimum value of 0 and a maximum value of 4. However, if I lock the cell, so that a user cannot manually enter a number, the form controls no longer work. Is there any way to prevent a user from manually typing in a number, but still allow the form controls to limit only numbers between 0-4?
I was able to solve this on my own. Navigate to the Data Ribbon, then select Data Validation. Allow a whole number and set the data between a minimum of "0" and a Maximum of "4" Then, set an error alert stating the business rule as to why the value can only be between 0 and 4. The user will be unable to navigate off of the cell without changing the value between it's minimum and maximum values.

Excel Formula If functionHelp

Help Main Sheet
First Data
Main Data Label
Why Hello!
I am having a hard time completing an in-depth if function. Here is my issue:
I have a list in Column A with drop down buttons. Out of those 60 items, I need 5 of them to have a running total IF they are selected. Currently my function looks like this but obviously isn't working if I am asking here. It will not keep a running total in the same cell if any combination are chosen. IE if 1 is chosen cell value = 4. If 2 are chosen cell value = 8
=IF(OR(COUNTIF(Testing!C12:E27,CharacterSkills!B4),COUNTIF(Testing!C12:E27,CharacterSkills!B6),COUNTIF(Testing!C12:E27,CharacterSkills!B16),COUNTIF(Testing!C12:E27,CharacterSkills!B25),COUNTIF(Testing!C12:E27,CharacterSkills!B28),COUNTIF(Testing!C12:E27,CharacterSkills!B31)),A18+4,0)
Specifics:
MainSheet: Cell C12:E27 are drop downs pulling from "Data Table" Photo (The selection is filtered by Cell E6 (Class). Using Data Validation =OFFSET(CharacterSkills!$A$1,MATCH($E$5,CharacterSkills!$A:$A,0)-1,1,COUNTIF(CharacterSkills!$A:$A,$E$5),1)
First Data: Cell B18 is the cell I would like to keep a running total in. For example, everytime Arcane Magic, or Divine Magic is selected I would like it to add 4 to that cell each time
Data Table: This is the main data table for the drop downs on the MainSheet.
Thanks for all your help!
In cell B18 on the sheet "First Data", input the formula below. This will work for the test case given. If you want this to be more dynamic (ie input all the things that necessitate a +4 in a range and just reference that) you will need a more complex formula. I am happy to help with that as well, but thought I would give you this, which fits the criteria above.
=(Countifs(Testing!C12:E27,"Arcane Magic") + Countifs(Testing!C12:E27,"Divine Magic"))*4
More complicated answer:
Let's say instead of stringing together Countifs() statement, you had a range Testing!XFD1:XFD2 and in XFD1 you have Arcane Magic and in XFD2 you have Divine Magic. If this were the case, you could instead use:
{=SUM(COUNTIFS(Testing!C12:E27,Testing!XFD1:XFD2))*4}
Note this must be entered using Shift + Ctrl + Enter. The curly braces will be input when you enter the formula, you do not enter those on your own.

Excel: Dependent Dropdown Lists on Dynamic Content

I've imported a list of clients and their websites from the Google Analytics (GA) API in the following format:
Account Profile
Client 1 www.client1.com
Client 1 sub.client1.com
Client 1 tst.client1.com
Client 2 www.client2.com
Client 3 www.client3.com
Client 3 sub.client3.com
What I need is a dropdown list with the unique accounts names and then a second dropdown list with the dependent profiles of the chosen account. Something that looks like this:
Account Profile
Client 1 www.client1.com
sub.client1.com
tst.client1.com
We add accounts and profiles to GA all the time, so the list will need to be refreshed every time we run the report.
How would I go about doing this?
As long as you have this list sorted by Account, you can use a mixture of Offset CountA to give you all the ranges you need.
Steps would be:
a. Get unique values from Account column (i'm using VBA for this step but you could use Frequency formula to mash this too -- I'd avoid it if you can use VBA for this). Something along the lines:
Sub FindUniqueValues(SourceRange As Range, TargetCell As Range)
SourceRange.AdvancedFilter xlFilterCopy, , TargetCell, True
End Sub
(I've called this from my worksheet_change event for ease but if you are using vba to pull G.A. data, just integrate into that)
b. Feed this to Named Range (Say AccountsRange) that has the forumla =$D$2:INDEX($D$2:$D$5000,COUNTA($D$2:$D$5000)) -- This assumes you specified D1 as TargetCell for previous step and unique values won't be more than 4999 (1st value is row title in my case -- Hence starting from D2)
c. Add this Named Range AccountsRange as source for Data Validation List -- Your account combo box is done at this point. I'm going to assume you put this combo box in E2 and I'll build on this to derive the second ComboBox
d. Create a new Named Range say ProfilesRange with formula =INDEX($B$1:$B$5000,MATCH($E$2,$A$1:$A$5000,0),1):INDEX($B$1:$B$5000,COUNTIF($A‌​$1:$A$5000,$E$2)+MATCH($E$2,$A$1:$A$5000,0)-1,1)
Note: if you copy paste from here the above formula will contain a line-break invisible character after COUNTIF($A and excel will complain about invalid formula, just retype $A$1 part of COUNTIF and it should be fine
A2 is the start of Account column of G.A. imported data (A1 being the title and assuming maximum of 4999 data rows here) E2 is the Comboboxed cell from previous AccountsRange dropdown step. -1 in Match step is needed as the offset needs to be 0 for first value row and not 1 which will be returned from Match. Second 1 is column offset (it can be more if you need to hop several columns to get secondary data). CountIf is pretty self explanatory :) This basically gets us the number of cells we need in final range from the starting point.
e. Create your new Data Validation List that uses ProfilesRange as its source and your secondary combo box is done.
Issues that may arise:
When you change Accounts Combobox, Profiles combobox will probably error out as the values in profiles are unlikely to be present in new client. You could either ignore the error (it will fix itself once you select correct value from newly refreshed dropdown or throw a bit more of VBA fairy dust in there to clear the drop down cell when the value changes in E2.
Data Validation List compalains about evaluating to an error when you try to setup ProfilesRange. It is safe to ignore this error and continue. It basically means nothing computable was returned by ProfilesRange (most probably because you haven't selected anything in AccountsRange that actually computes to a ProfilesRange -- of course assuming your actual cell ranges for formulae used here are actually correct for your sheet)
Thanks to osknows for his tip and improvement on forumlae (in comments below): Avoid use of OFFSET its very slow over large ranges and is volatile. =OFFSET($D$2,0,0,COUNTA($D$2:$D$5000) can be replaced with =$D$2:INDEX($D$2:$D$5000,COUNTA($D$2:$D$5000)) for the named range. (this tip has been incorporated into this solution now, so you won't see the original Offset forumlae unless you check version history)

Resources