ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Can I enter a "Y" in a cell and have it return a "YES"? How? (https://www.excelbanter.com/excel-programming/369811-can-i-enter-y-cell-have-return-yes-how.html)

rbbbbeee

Can I enter a "Y" in a cell and have it return a "YES"? How?
 
I am creating a spreadsheet where i have to enter information into a cell.
Instead of having to type the whole word "YES", I would like to be able to
enter just the letter "Y" or say the number "1" and have it display the word
"YES". This would save me great amounts of time. Is this possible to do?
If so, how?

Greg Wilson

Can I enter a "Y" in a cell and have it return a "YES"? How?
 
Assumed is that you want this behavior to occur in column B. Paste to the
worksheet's class module: Right click the worksheet tab Select View Code
Paste to the code module.

Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If .Count 1 Or .Column < 2 Then Exit Sub
If LCase(Trim(.Value)) = "y" Or _
LCase(Trim(.Value)) = "yes" Then
.Value = "Yes"
End If
End With
End Sub

Regards,
Greg


Ken Johnson

Can I enter a "Y" in a cell and have it return a "YES"? How?
 

Hi, If you have the "Allow AutoComplete for cell values" option enabled
then you will only have to fully type the first "Yes" and firsst "No".
After that "Y" + Enter will give "Yes" and "N" + Enter will give "No".

Go Tools|Options|Edit then make sure that option is ticked|OK

Ken Johnson


Greg Wilson

Can I enter a "Y" in a cell and have it return a "YES"? How?
 
Sorry. I forgot to disable EnableEvents. Should be:

Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If .Count 1 Or .Column < 2 Then Exit Sub
If LCase(Trim(.Value)) = "y" Or _
LCase(Trim(.Value)) = "yes" Then
Application.EnableEvents = False
.Value = "Yes"
Application.EnableEvents = True
End If
End With
End Sub
"Greg Wilson" wrote:

Assumed is that you want this behavior to occur in column B. Paste to the
worksheet's class module: Right click the worksheet tab Select View Code
Paste to the code module.

Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If .Count 1 Or .Column < 2 Then Exit Sub
If LCase(Trim(.Value)) = "y" Or _
LCase(Trim(.Value)) = "yes" Then
.Value = "Yes"
End If
End With
End Sub

Regards,
Greg



All times are GMT +1. The time now is 07:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com