Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Delete words in cell if that word is in red

Hi,

I would like to run a macro that looks at each word in a cell, and if
that word is in red, delete the word

Can anyone help me do this?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 126
Default Delete words in cell if that word is in red

Without actually doing this I can tell you how I would go about finding
the solution:
Turn on your macro recorder.
Type some words in a cell, making some letters red in the middle of the text.
Turn off the recorder.

Look at the recorded code to see what property makes the font red for
certain letters

Then use that property to loop through the text in a cell and delete
any character with that property.

Hope this helps get you started

"kaiser" wrote:

Hi,

I would like to run a macro that looks at each word in a cell, and if
that word is in red, delete the word

Can anyone help me do this?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default Delete words in cell if that word is in red

This might do it but you may be left with extra spaces.

Sub DelRed()
Dim i As Integer
Dim RStr As String
For i = 1 To Len(ActiveCell.Value)
If ActiveCell.Characters(i, 1).Font.ColorIndex < 3 Then
RStr = RStr & Mid(ActiveCell.Value, i, 1)
End If
Next i
ActiveCell.Value = RStr
End Sub

Hope this helps

Regards
Rowan

cush wrote:
Without actually doing this I can tell you how I would go about finding
the solution:
Turn on your macro recorder.
Type some words in a cell, making some letters red in the middle of the text.
Turn off the recorder.

Look at the recorded code to see what property makes the font red for
certain letters

Then use that property to loop through the text in a cell and delete
any character with that property.

Hope this helps get you started

"kaiser" wrote:


Hi,

I would like to run a macro that looks at each word in a cell, and if
that word is in red, delete the word

Can anyone help me do this?


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Delete words in cell if that word is in red

Interesting. For this demo I have some text in H7 , "This is a test for
color", where the word test is colored red.
On running th eprocedure called test, the clee's value becomes 'this is a
for color"

Option Explicit
Sub test()

Dim target As Range
Set target = Range("H7")
target.Value = RemoveColor(target, vbRed)

End Sub

Function RemoveColor(source As Range, iColor As Long) As String
Dim text As Variant, bit As String
Dim index As Long
Dim pos As Long
text = Split(source, " ")
For index = LBound(text, 1) To UBound(text, 1)
pos = InStr(pos + 1, source, text(index))
If source.Characters(pos, Len(text(index))).Font.Color = iColor Then
text(index) = ""
End If
Next
RemoveColor = Join(text, " ")
End Function


"kaiser" wrote:

Hi,

I would like to run a macro that looks at each word in a cell, and if
that word is in red, delete the word

Can anyone help me do this?


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 copy the first word or two words from a cell containing a complete sentence to another cell jonny Excel Discussion (Misc queries) 7 May 19th 23 03:43 AM
How to delete the first word in every cell in a column Berit Excel Worksheet Functions 2 June 12th 07 12:38 PM
Delete all contents of cell but one word Hayette Hasham Excel Discussion (Misc queries) 5 January 18th 06 08:20 AM
delete cell that doesn't contain a specific word [email protected] Excel Discussion (Misc queries) 1 October 12th 05 05:54 AM
Separate last word in cell with more than 2 words? Pat Mayton Excel Worksheet Functions 2 March 24th 05 03:37 PM


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