Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Substring to replace string

Hi,

I am trying to figure out an easy way to create an excel macro that will
take a substring and replace the string with that substring. Ex:
47130-5240 (original) take the first 5 characters and replace the
original value with only those first 5 characters. So the result would
be 47130 in that cell.

Any ideas???

Thanks,

Andrew

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Substring to replace string

activeCell.Value = Left(activeCell.Value,5)

--
Regards,
Tom Ogilvy

"Andrew Slentz" wrote in message
...
Hi,

I am trying to figure out an easy way to create an excel macro that will
take a substring and replace the string with that substring. Ex:
47130-5240 (original) take the first 5 characters and replace the
original value with only those first 5 characters. So the result would
be 47130 in that cell.

Any ideas???

Thanks,

Andrew

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Substring to replace string

Hmm... Thanks a bunch. This makes sense but how do I apply that to a
specific column of an entire spreadsheet???

I am so lost...

Thanks,

Andrew

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Substring to replace string

Hi
try something like
sub foo()
dim rng as range
dim cell as range
application.screenupdating=false
set rng = activesheet.range("A1:A100")
for each cell in rng
if len(cell.value)=5 then
cell.value =left(cell.value,5)
end if
next
application.screenupdating=true
end sub

--
Regards
Frank Kabel
Frankfurt, Germany


Andrew Slentz wrote:
Hmm... Thanks a bunch. This makes sense but how do I apply that to

a
specific column of an entire spreadsheet???

I am so lost...

Thanks,

Andrew

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!


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
Edit REplace String Tami Excel Worksheet Functions 2 September 25th 09 08:20 PM
search a string as substring and give adjacent values Eddy Stan Excel Worksheet Functions 1 June 23rd 08 03:05 PM
How do I replace last numeric string from a alphanumeric string? Christy Excel Discussion (Misc queries) 3 August 11th 06 12:17 AM
How to get rid of string which contain a substring like 'PO BOX'. dukejas[_4_] Excel Programming 2 November 11th 03 02:36 AM
replace a number with a string from database K.Martens Excel Programming 1 November 6th 03 10:27 PM


All times are GMT +1. The time now is 09:40 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"