Home |
Search |
Today's Posts |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I know you asked for a Select Case solution, but (assuming you are only
talking about single letter codes) there is a more compact coding solution available using the Choose function for what you want to do... Private Sub Worksheet_Change(ByVal Target As Range) Application.EnableEvents = False If Target.Column = 2 Then Target.Value = Choose(InStr(1, "wgd", _ Target.Value, vbTextCompare), "WIDGETS", "GIDGETS", "DIGITS") Application.EnableEvents = True End Sub I added one more item to make it more obvious how to structure the code. The "wgd" correspond to the codes you want to type in the cell ("w" for WIDGETS, "g" for GIDGETS and "d" for DIGITS) where the letter you type into the cell can be either upper or lower case (that is what the vbTextCompare argument in the InStr function call makes possible). The order of the letters in the "wgd" string must be the same as the listed order of what you want these letters replaced with in the arguments to the Choose function (as my code shows). -- Rick (MVP - Excel) "John" wrote in message ... I'm trying to use a Select Case in a Private Sub Worksheet_Change event to do the following: if I type w in a cell in col B, I want to replace it with WIDGETS if I type g in a cell in col B, I want to replace it with GIDGETS seems like it should be simple but I can't come up with the code. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Use Select / Case to find certain text | Excel Programming | |||
Change the text from lower case to upper case in an Excel work boo | Excel Discussion (Misc queries) | |||
Select Case with Text | Excel Programming | |||
Select Case from Text Box Input | Excel Programming | |||
Select Case from Text Box Input | Excel Programming |