Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 123
Default Trimming leading character from string and replace underscore withdashes

Dear Experts:

My worksheet has numerous entries, which all have the following form:

_##_###_##_## (e.g. _90_237_44_44 or _40_443_22_77)

I would like to run a macro that changes the SELECTED CELLS from
_##_###_##_## to ##-###-###-##

That is ...
.... the first underscore has to be dropped
.... all the other underscores have to be replaced with dashes.

I got a formula alternative but I'd rather run a macro that performs
the following on SELECTED CELLS:

SUBSTITUTE(MID(A1,2,LEN(A1)),"_","-")

Help is much appreciated. Thank you very muc in advance.

Regards, Andreas
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Trimming leading character from string and replace underscore with dashes

This code should do that for you...

Dim Cell As Range
......
......
For Each Cell In Selection
Cell.Value = Replace(Mid(Cell.Value, 2), "_", "-")
Next

--
Rick (MVP - Excel)



"andreashermle" wrote in message
...
Dear Experts:

My worksheet has numerous entries, which all have the following form:

_##_###_##_## (e.g. _90_237_44_44 or _40_443_22_77)

I would like to run a macro that changes the SELECTED CELLS from
_##_###_##_## to ##-###-###-##

That is ...
... the first underscore has to be dropped
... all the other underscores have to be replaced with dashes.

I got a formula alternative but I'd rather run a macro that performs
the following on SELECTED CELLS:

SUBSTITUTE(MID(A1,2,LEN(A1)),"_","-")

Help is much appreciated. Thank you very muc in advance.

Regards, Andreas


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 99
Default Trimming leading character from string and replace underscorewith dashes

Hi Andreas,

You could try something like,

Sub UnderscoreToDash()
Dim r As Range

For Each r In Selection
r.Value = Replace(Mid(r.Text, 2), "_", "-")
Next
End Sub

HTH,

Wouter
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 123
Default Trimming leading character from string and replace underscorewith dashes

On Apr 19, 8:14*pm, Wouter HM wrote:
Hi Andreas,

You could try something like,

Sub UnderscoreToDash()
*Dim r As Range

*For Each r In Selection
* r.Value = Replace(Mid(r.Text, 2), "_", "-")
*Next
End Sub

HTH,

Wouter


Hi,

that's it! Great! Thank you very much for your professional help.
Regards, Andreas
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 123
Default Trimming leading character from string and replace underscorewith dashes

On Apr 19, 8:12*pm, "Rick Rothstein"
wrote:
This code should do that for you...

Dim Cell As Range
.....
.....
For Each Cell In Selection
* Cell.Value = Replace(Mid(Cell.Value, 2), "_", "-")
Next

--
Rick (MVP - Excel)

"andreashermle" wrote in message

...



Dear Experts:


My worksheet has numerous entries, which all have the following form:


_##_###_##_## (e.g. _90_237_44_44 or _40_443_22_77)


I would like to run a macro that changes the SELECTED CELLS from
_##_###_##_## to ##-###-###-##


That is ...
... the first underscore has to be dropped
... all the other underscores have to be replaced with dashes.


I got a formula alternative but I'd rather run a macro that performs
the following on SELECTED CELLS:


SUBSTITUTE(MID(A1,2,LEN(A1)),"_","-")


Help is much appreciated. Thank you very muc in advance.


Regards, Andreas- Hide quoted text -


- Show quoted text -


Rick,

Perfect. Thank you very much for your great help. Regards, Andreas
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
replace last character in string ernie Excel Programming 5 October 27th 09 03:55 PM
How to replace a formula string with * in the leading position? Seaq Excel Worksheet Functions 3 June 12th 09 04:45 PM
more character 160 leading/trailing find/replace problems M Excel Discussion (Misc queries) 6 October 31st 08 11:06 AM
Replace font of one character in a string PaulS Excel Programming 3 January 13th 07 03:45 AM
How replace a character in a string of characters? Chet Excel Programming 6 December 6th 06 01:54 AM


All times are GMT +1. The time now is 06:23 PM.

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"