LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default select case to replace text with different text

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use Select / Case to find certain text marlea[_10_] Excel Programming 4 February 2nd 06 12:05 PM
Change the text from lower case to upper case in an Excel work boo dave01968 Excel Discussion (Misc queries) 2 December 9th 05 09:09 AM
Select Case with Text Marie Excel Programming 3 February 10th 05 05:31 PM
Select Case from Text Box Input mackerma[_2_] Excel Programming 1 October 19th 04 08:14 PM
Select Case from Text Box Input mackerma Excel Programming 0 October 15th 04 08:50 PM


All times are GMT +1. The time now is 09:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"