How to get a cell to display a default value

Anonymous
2021-07-27T22:49:43+00:00

Hello,

I am trying to create a spreadsheet where a user must select Yes/No in a column (column G), but if the user doesn't select an answer - the cell would default to "No Answer". Also, if the user selects an answer, but then changes his mind and deletes the answer - the cell should default to "No Answer". In other words, in column G, every cell at all times should have either "No Answer" or "Yes" or "No" - there should be no blank cells at any point.

I tried using a formula in cells like =IF(G3="", "No Answer", G3) , but that's easy to delete, leaving the cell blank. What other options are out there?

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. Anonymous
    2021-07-27T23:07:21+00:00

    Data Validation will get you part way but you will have to add VBA to make sure the cells always have an answer.

    Select all the cells of concern in column G and choose Data, (Data Tools) Data Validation and set up the following:

    I give you some code in a while.

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2021-07-27T23:23:32+00:00

    Add this code to the appropriate code sheet:

    I have named the range in column G which need answers "Answer"

    To get to the VBA area press Alt+F11, find your workbook on the Project Explorer window on the left and double click the Sheet you are working with. In top dropdown on the left choose Worksheet and on the right choose Change. Add the 3 lines of code as shown above.

    4 people found this answer helpful.
    0 comments No comments
  3. Anonymous
    2021-07-28T13:29:53+00:00

    Thank you, Shane. I applied the coding and the data validation, but I'm still able to hit the delete button and clear the cells. Was I supposed to hit save somewhere after entering the lines of code? - seems like there was a step missing b/c I just entered the code and then clicked out of the window (didn't see a "save" or equivalent button)

    1 person found this answer helpful.
    0 comments No comments
  4. Anonymous
    2021-07-30T02:17:09+00:00

    You need to name the range where these answer are going to be located. I named that range "Answer". The name of the range must match the entry in the code:

    Private Sub Worksheet_Change(ByVal Target As Range)

    If Intersect(Target, Range("**Answer**")) Is Nothing Then 
    
    ElseIf Target = "" Then Target = "No Answer" 
    
    End If 
    

    End Sub

    You can name the range anything you want but it then you must enter that name in place of the bolded entry in the code above.

    You name a range by selecting the range in the spreadsheet and then clicking on the Name box and typing the name into the box and pressing Enter.

    In this figure I have named the range A1:A10 Answer.

    If you already have a name Answer, but referencing a different location than where you want it, choose Formulas, Name Manager select the name and Delete it. Then add your new one as I described above.

    2 people found this answer helpful.
    0 comments No comments
  5. Anonymous
    2021-08-09T19:53:13+00:00

    Shane, it worked. This is great - thank you!

    0 comments No comments