Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 99
Default Macro to remove word from text in a cell

Hi Everyone,

I posted recently to ask how to add a word to a line of text in a cell using
a recorded macro that would run on a number of workbooks where the text was
slightly different but needed "provisional adding at the end.

Gary's Student kindly provided this

Select the cells and run:

Sub prov()
For Each r In Selection
r.Value = r.Value & " Provisional"
Next
End Sub

Works brilliantly !!!

BUT now I need to remove the "Provisional" from the end of the line of text.
Wouldn't you know it :-)

Any ideas would be brilliant
Thanks
--
Mifty
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Macro to remove word from text in a cell

One way:

Public Sub RemoveProvisionalFromEndOfCellText()
Const sSearch As String = "* Provisional"
Dim rCell As Range
Dim nLen As Long
If TypeOf Selection Is Range Then
nLen = Len(sSearch) - 1
With Selection
On Error GoTo ErrorExit
For Each rCell In Intersect(.Cells, _
.Parent.UsedRange.SpecialCells( _
xlCellTypeConstants, xlTextValues))
With rCell
If .Text Like sSearch Then _
.Value = Left(.Text, Len(.Text) - nLen)
End With
Next rCell
End With
End If
ErrorExit:
End Sub



In article ,
Mifty wrote:

Hi Everyone,

I posted recently to ask how to add a word to a line of text in a cell using
a recorded macro that would run on a number of workbooks where the text was
slightly different but needed "provisional adding at the end.

Gary's Student kindly provided this

Select the cells and run:

Sub prov()
For Each r In Selection
r.Value = r.Value & " Provisional"
Next
End Sub

Works brilliantly !!!

BUT now I need to remove the "Provisional" from the end of the line of text.
Wouldn't you know it :-)

Any ideas would be brilliant
Thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 99
Default Macro to remove word from text in a cell

Thank you JE,

I love your website.

I wasn't really expecting to get an answer on this one and thought I was
going to have to trawl through all the workbooks manually deleting it. So
thank you to both JE and Matthew.

I'm always amazed by the generosity and also the different approaches and
although I'm just scabbling on the bottom rung I'm finding these forums a
fantastic learning resource. Problem is that the more I learn the more I
realise just how little I know.

Cheers
--
Mifty


"JE McGimpsey" wrote:

One way:

Public Sub RemoveProvisionalFromEndOfCellText()
Const sSearch As String = "* Provisional"
Dim rCell As Range
Dim nLen As Long
If TypeOf Selection Is Range Then
nLen = Len(sSearch) - 1
With Selection
On Error GoTo ErrorExit
For Each rCell In Intersect(.Cells, _
.Parent.UsedRange.SpecialCells( _
xlCellTypeConstants, xlTextValues))
With rCell
If .Text Like sSearch Then _
.Value = Left(.Text, Len(.Text) - nLen)
End With
Next rCell
End With
End If
ErrorExit:
End Sub



In article ,
Mifty wrote:

Hi Everyone,

I posted recently to ask how to add a word to a line of text in a cell using
a recorded macro that would run on a number of workbooks where the text was
slightly different but needed "provisional adding at the end.

Gary's Student kindly provided this

Select the cells and run:

Sub prov()
For Each r In Selection
r.Value = r.Value & " Provisional"
Next
End Sub

Works brilliantly !!!

BUT now I need to remove the "Provisional" from the end of the line of text.
Wouldn't you know it :-)

Any ideas would be brilliant
Thanks


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default Macro to remove word from text in a cell

Hi, Mifty. Use this:

sub removeProv()
For each r in selection
r.value = replace(r.value," Provisional","")
next
End Sub

HTH,
Matthew Pfluger

"Mifty" wrote:

Hi Everyone,

I posted recently to ask how to add a word to a line of text in a cell using
a recorded macro that would run on a number of workbooks where the text was
slightly different but needed "provisional adding at the end.

Gary's Student kindly provided this

Select the cells and run:

Sub prov()
For Each r In Selection
r.Value = r.Value & " Provisional"
Next
End Sub

Works brilliantly !!!

BUT now I need to remove the "Provisional" from the end of the line of text.
Wouldn't you know it :-)

Any ideas would be brilliant
Thanks
--
Mifty

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Macro to remove word from text in a cell

While that may be exactly what the OP needs, note that it doesn't
discriminate between " Provisional" found at the beginning or middle of
a block of text, and the OP's specified end of the line of text.

In article ,
Matthew Pfluger wrote:

Hi, Mifty. Use this:

sub removeProv()
For each r in selection
r.value = replace(r.value," Provisional","")
next
End Sub

HTH,
Matthew Pfluger

"Mifty" wrote:

Hi Everyone,

I posted recently to ask how to add a word to a line of text in a cell
using
a recorded macro that would run on a number of workbooks where the text was
slightly different but needed "provisional adding at the end.

Gary's Student kindly provided this

Select the cells and run:

Sub prov()
For Each r In Selection
r.Value = r.Value & " Provisional"
Next
End Sub

Works brilliantly !!!

BUT now I need to remove the "Provisional" from the end of the line of
text.
Wouldn't you know it :-)

Any ideas would be brilliant
Thanks
--
Mifty



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 99
Default Macro to remove word from text in a cell

Thank you Matthew,

Just the job
Cheers
--
Mifty


"Matthew Pfluger" wrote:

Hi, Mifty. Use this:

sub removeProv()
For each r in selection
r.value = replace(r.value," Provisional","")
next
End Sub

HTH,
Matthew Pfluger

"Mifty" wrote:

Hi Everyone,

I posted recently to ask how to add a word to a line of text in a cell using
a recorded macro that would run on a number of workbooks where the text was
slightly different but needed "provisional adding at the end.

Gary's Student kindly provided this

Select the cells and run:

Sub prov()
For Each r In Selection
r.Value = r.Value & " Provisional"
Next
End Sub

Works brilliantly !!!

BUT now I need to remove the "Provisional" from the end of the line of text.
Wouldn't you know it :-)

Any ideas would be brilliant
Thanks
--
Mifty

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
How to remove spaces from a word in a cell Jerry Excel Discussion (Misc queries) 5 January 15th 07 08:11 PM
Remove 0D0A from cell with word Mariusz[_3_] Excel Programming 2 July 6th 06 03:00 PM
Macro to remove text Terry Pinnell Excel Discussion (Misc queries) 5 October 21st 05 11:34 PM
Function to remove a space from text in cell WITHOUT macro?? [email protected] Excel Worksheet Functions 5 May 28th 05 02:28 AM
How do I Remove bullets from text data in Excel cell with macro? David McRitchie Excel Programming 0 September 19th 04 09:22 PM


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