Want to be able to enter free text in a field if an IF statement is false?

soph12081

Board Regular
Joined
Oct 6, 2014
Messages
56
Hello

I have a spreadsheet and would like an IF statement (if possible) that allows the user to enter free text if the IF statement is false.

So I need it to say If E4=Mobile Shredder and H4=PS then select from drop down list. If not, then enter free text.

Any ideas? Is it possible?

Thank you in advance.

Sophie
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
A cell can have a formula or you can enter text. If you have a IF statement in a cell any text entered will overwrite the formula. You could use a change event to put a data validation list in the cell or remove it so any text can be entered based on your criteria.
 
Upvote 0
Code can be entered to run when a cell is changed.

https://msdn.microsoft.com/en-us/vba/excel-vba/articles/worksheet-change-event-excel

This code would check what cell was changed. If it is E4 or H4. If the cell is one if the two it tests what is in the cell and either sets up data validation or cleared data validation to allow any text to be entered. I assumed A4 was the cell.
Right click on the tab and select view code.
past the code in the VBA editor.
the file must be saved as a macro enabled file type such as .xlsm

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("E4")) Is Nothing Or Not Intersect(Target, Range("H4")) Is Nothing Then 'test if the cell that changed is E4 or H4
    If UCase(Range("E4")) = "MOBILE SHREDDER" And UCase(Range("H4")) = "PS" Then 'Test what is in the cells
        Range("A4").ClearContents 'change the cell reference to where you want. this clears the cell
        With Range("A4").Validation 'code for data validation with list of allowable values in S2:S8. change if need
            .Delete
            .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
            xlBetween, Formula1:="=$S$2:$S$8"
            .IgnoreBlank = True
            .InCellDropdown = True
            .InputTitle = ""
            .ErrorTitle = ""
            .InputMessage = ""
            .ErrorMessage = ""
            .ShowInput = True
            .ShowError = True
        End With
    Else
        Range("A4").Validation.Delete 'delete data validation if condition not met
        Range("A4").ClearContents 'cleares cell
    End If

End If

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top