Murray needs a way to control the entry of data into cell B1. If cell A1 contains the capital letter "A," then the user should be able to enter data into cell B1. If cell A1 contains anything but the capital letter "A," then no data entry should be allowed in cell B1 and cell B1 should show "N/A" (not the error value #N/A, but the letters "N/A").
There are two ways to go about this. One way is to use a macro that checks to see if A1 contains "A" or not. If it does, then the macro keeps whatever is in cell B1, unless B1 had previously been set to "N/A." (If it had, then B1 is cleared.) If A1 does not contain "A," then whatever is in cell B1 is replaced with the characters "N/A."
Private Sub Worksheet_Change(ByVal Target As Range) Dim sTemp As String If Target.Address(False, False) = "A1" Or _ Target.Address(False, False_ = "B1" Then 'Store B1's text in variable sTemp = Range("B1").Text Application.EnableEvents = False If Range("A1").Text = "A" Then If sTemp = "N/A" Then Range("B1") = "" Else Range("B1") = "N/A" End If Application.EnableEvents = True End If End Sub
Note that this is simply one macro-based approach; there are many other approaches that could be used, depending on what behavior you want to have take place if either cell A1 or B1 are selected. In the case of this macro, it should be saved in the ThisWorkbook module so that it triggers whenever something is changed in the worksheet.
The other approach you can use doesn't involve macros at all. Instead, it relies on conditional formatting. Follow these steps:
Figure 1. The New Formatting Rule dialog box.
The custom format you defined in step 9 causes Excel to display the letters "N/A" when the value is a number (positive, negative, or zero) or text. Since you set all 4 conditions to the same thing, then all of them will display "N/A." This approach changes the display, but it still allows the user to enter a value into cell B1—it just won't display properly unless the first letter in cell A1 is "A."
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13457) applies to Microsoft Excel 2007, 2010, 2013, and 2016.
Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!
You may use Excel to track due dates for a variety of purposes. As a due date approaches, you may want that fact drawn to ...
Discover MoreWhen you apply conditional formatting to the cells in your worksheet, those rules can seem a bit fragile at times. For ...
Discover MoreSometimes the hardest part of getting your conditional formatting rules to work properly is figuring out the proper way ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2016-07-18 04:18:20
greenbottle
Using the conditional formatting approach, if the text in A1 is a word that begins with A then the text in B1 will be displayed rather than "N/A".
If you want the text in B1 to be displayed only when the text in A1 is specifically the letter A, rather than any word that starts with A, then the formula should be simplified to =NOT(EXACT(A1,"A")).
2016-07-17 19:29:56
Truly Gone
In the Windows version of Excel it is under Format Cells > Number > Custom and then under the word "Type:" you will see a box with the word "General". Replace "General with the "N/A" stuff in the tip.
That being said, I can't get the N/A to display as a conditional format. So I used the suggested helper column to evaluate column A and let me know if it is ok to enter in column B. Much easier.
2016-07-17 05:57:44
Stephen Argent
Where is the "Type box" referred to in Step 9 of this tip? When I select "Custom" from the list of formatting options, the only choices I have are to set the font style, border or fill. There is no option to change the cell's text formatting.
I'm using Excel 2016 for Mac.
Thanks
2016-07-16 09:32:24
Col Delane
The second approach using Conditional Formatting doesn't address Murray's requirement, as it merely displays (by formatting) the desired outcome rather than have the cell (B1) contain the underlying value! This will produce an incorrect result in subsequent calculations that reference B1.
A better option would be to have the user input their data in a helper cell (say C1), and the use an IF function formula in B1 to return the desired result,viz:
=IF( AND( EXACT(A1,UPPER(A1)),A1="A" ),C1,"N/A" )
I haven't tested it, but it may also be possible to use a variation of this formula as a Data Validation Custom setting applied to B1 that would accept any value if A1 = "A" but only "N/A" if not.
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2021 Sharon Parq Associates, Inc.
Comments