ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Substring to replace string (https://www.excelbanter.com/excel-programming/301202-substring-replace-string.html)

Andrew Slentz[_2_]

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!

Tom Ogilvy

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!




Andrew Slentz[_2_]

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!

Frank Kabel

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!




All times are GMT +1. The time now is 04:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com