Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
cdb cdb is offline
external usenet poster
 
Posts: 62
Default Changing individual chars within a cell

I am trying to write a bit of code that will look at a cell and covert what's in the cell to some sort of code.

e.g. Hello Goodbye Yes No

The above words are in different cells, and need converting to a different code, for example H is 1, e is 2, l is 3 and 0 is 4, so Hello would be 12334

The entries to the cells will be different, so I can't just do a select case and have Hello as one of them. Is there any way of doing a select case type statement, but for it to look at individual characters in a cell and cycle through until it's finished and then move onto the next cell??

Or is there an easier way of doing this?? A simple EditReplace is not sufficient!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Changing individual chars within a cell

Sub test()
Dim rng As Range, strCode As String, str As String, i As Long

For Each rng In Range("A1:A5")
strCode = ""
For i = 1 To Len(rng.Value)
Select Case LCase(Mid(rng.Value, i, 1))
Case "h": str = 1
Case "e": str = 2
Case "l": str = 3
Case "o": str = 4
End Select
strCode = strCode & str
Next
rng.Value = strCode
Next
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"cdb" wrote in message
...
I am trying to write a bit of code that will look at a cell and covert

what's in the cell to some sort of code.

e.g. Hello Goodbye Yes No

The above words are in different cells, and need converting to a different

code, for example H is 1, e is 2, l is 3 and 0 is 4, so Hello would be 12334

The entries to the cells will be different, so I can't just do a select

case and have Hello as one of them. Is there any way of doing a select case
type statement, but for it to look at individual characters in a cell and
cycle through until it's finished and then move onto the next cell??

Or is there an easier way of doing this?? A simple EditReplace is not

sufficient!


  #3   Report Post  
Posted to microsoft.public.excel.programming
cdb cdb is offline
external usenet poster
 
Posts: 62
Default Changing individual chars within a cell

Many Thanks - that works a treat

"Rob van Gelder" wrote:

Sub test()
Dim rng As Range, strCode As String, str As String, i As Long

For Each rng In Range("A1:A5")
strCode = ""
For i = 1 To Len(rng.Value)
Select Case LCase(Mid(rng.Value, i, 1))
Case "h": str = 1
Case "e": str = 2
Case "l": str = 3
Case "o": str = 4
End Select
strCode = strCode & str
Next
rng.Value = strCode
Next
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"cdb" wrote in message
...
I am trying to write a bit of code that will look at a cell and covert

what's in the cell to some sort of code.

e.g. Hello Goodbye Yes No

The above words are in different cells, and need converting to a different

code, for example H is 1, e is 2, l is 3 and 0 is 4, so Hello would be 12334

The entries to the cells will be different, so I can't just do a select

case and have Hello as one of them. Is there any way of doing a select case
type statement, but for it to look at individual characters in a cell and
cycle through until it's finished and then move onto the next cell??

Or is there an easier way of doing this?? A simple EditReplace is not

sufficient!



Reply
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
How to truncate list of meaningful words greater than 15 chars tomeaningful words of 8 chars. Babloo Excel Worksheet Functions 4 April 29th 11 11:27 PM
limit # of chars in a cell soonic Excel Discussion (Misc queries) 1 March 22nd 10 11:21 AM
Mass Changing whole sheets individual cell references Ryan Excel Discussion (Misc queries) 2 January 16th 09 03:59 PM
Copy sheets with more than 255 chars in a cell? Chem Mitch Excel Worksheet Functions 1 April 16th 05 01:17 AM
1160 Max Chars per cell ? Workaround ? Neil Excel Programming 5 February 18th 04 01:23 PM


All times are GMT +1. The time now is 08:49 AM.

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

About Us

"It's about Microsoft Excel"