Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default Replace characters from cell values

Hi all

I would like to remove the number and dash from the cell values as
follows:

1 - Apples
2 - Oranges
3 - Bananas
etc

I can't use the MID function as is as the digit prefix can be more than
1 character. I was thinking of the REPLACE function but it doesn't
seem to accept a wildcard character (eg "* - ").

Any ideas appreciated.

Paul Martin

Melbourne, Australia

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default Replace characters from cell values

I should mention that I have achieved the above using the following
code, but was wondering if there is something function that will do it
more simply.

For Each rngCell In rngBrands.Cells
sBrand = Replace(rngCell.Value, " - ", "")
Do
sBrand = Mid(sBrand, 2)
Loop While IsNumeric(Left(sBrand, 1))

lstBrands.AddItem sBrand
Next rngCell

Paul Martin
Melbourne, Australia

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Replace characters from cell values

What about =MID(A1,FIND("-",A1)+2,LEN(A1)-(FIND("-",A1)+1))

Hope this helps
Rowan

"Paul Martin" wrote:

I should mention that I have achieved the above using the following
code, but was wondering if there is something function that will do it
more simply.

For Each rngCell In rngBrands.Cells
sBrand = Replace(rngCell.Value, " - ", "")
Do
sBrand = Mid(sBrand, 2)
Loop While IsNumeric(Left(sBrand, 1))

lstBrands.AddItem sBrand
Next rngCell

Paul Martin
Melbourne, Australia


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default Replace characters from cell values

Hi Rowan

I was after a VBA solution, but I have adapted your suggestion as
follows, and it works fine.

sBrand = Mid(sBrand, WorksheetFunction.Find("-", sBrand) + 2)

Thanks

Paul Martin
Melbourne, Australia

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Replace characters from cell values

You may want to look at VBA's InStr function. Then you don't have to use the
worksheet.find.

Paul Martin wrote:

Hi Rowan

I was after a VBA solution, but I have adapted your suggestion as
follows, and it works fine.

sBrand = Mid(sBrand, WorksheetFunction.Find("-", sBrand) + 2)

Thanks

Paul Martin
Melbourne, Australia


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default Replace characters from cell values

Hi Dave

Thanks. Yes, I should have thought of Instr. Better solution than
what I used.

Regards

Paul Martin
Melbourne, Australia

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
Find and Replace Cell Values Jeff Excel Discussion (Misc queries) 3 March 23rd 10 01:46 PM
Find and replace specific characters within a cell based on positi ccgsuper Excel Discussion (Misc queries) 2 January 20th 09 02:34 PM
How do you find and replace tab characters in a cell in Excel? Ryk Excel Discussion (Misc queries) 1 March 28th 06 09:36 PM
How can I replace 2 of 5 characters within an cell in MS Excel? pmhall Excel Worksheet Functions 8 June 8th 05 09:07 PM
Append Text to Cell Values Using Replace Ngan Excel Discussion (Misc queries) 4 June 4th 05 08:30 PM


All times are GMT +1. The time now is 10:33 AM.

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"