ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Partial search and replace? (https://www.excelbanter.com/excel-discussion-misc-queries/42698-partial-search-replace.html)

Jamie Furlong

Partial search and replace?
 
Problem:
Loads of descriptions came in trimmed at 64 chars. At the end of most items,
there is the line "This includes free delivery".
But most times, it's been chopped. So it might be
This includes free delivery
This includes fre
Thi
etc. So I don't know the left or right chars to trim to neaten this up.
So I thought wildcard or regex find and replace would do, but it doesn't
seem to want to work like that with me! I've tried searching for phrases
like "partial find and replace" on this forum, but to no avail. I've got
4500 lines to do, so I'd rather not do it by hand!

Thanks.



Ian

Assuming the data you want to keep always ends in a period "." , this should
work for you.

Sub Trim_to_period()
c = 1 ' Change to suit column number (A=1, B=2 etc.)
For r = 1 To 7 ' Change to suit row range
Do While Right(Cells(r, c), 1) < "."
If (Cells(r, c) = "") Then GoTo continue
Cells(r, c).Value = Left(Cells(r, c), Len(Cells(r, c)) - 1)
Loop
continue:
Next
End Sub

--
Ian
--
"Jamie Furlong" wrote in message
...
Problem:
Loads of descriptions came in trimmed at 64 chars. At the end of most
items, there is the line "This includes free delivery".
But most times, it's been chopped. So it might be
This includes free delivery
This includes fre
Thi
etc. So I don't know the left or right chars to trim to neaten this up.
So I thought wildcard or regex find and replace would do, but it doesn't
seem to want to work like that with me! I've tried searching for phrases
like "partial find and replace" on this forum, but to no avail. I've got
4500 lines to do, so I'd rather not do it by hand!

Thanks.




Martin P

If the "This includes" part is always within brackets:
=SUBSTITUTE(A1, MID(A1,FIND("(",A1),LEN(A1)-FIND("(",A1)+1),"")
and copy down.

"Jamie Furlong" wrote:

Problem:
Loads of descriptions came in trimmed at 64 chars. At the end of most items,
there is the line "This includes free delivery".
But most times, it's been chopped. So it might be
This includes free delivery
This includes fre
Thi
etc. So I don't know the left or right chars to trim to neaten this up.
So I thought wildcard or regex find and replace would do, but it doesn't
seem to want to work like that with me! I've tried searching for phrases
like "partial find and replace" on this forum, but to no avail. I've got
4500 lines to do, so I'd rather not do it by hand!

Thanks.





All times are GMT +1. The time now is 09:26 PM.

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