Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-03-2023, 11:48 AM
Harvi007 Harvi007 is offline Select single word to left of comma and change its font colour Windows 11 Select single word to left of comma and change its font colour Office 2019
Novice
Select single word to left of comma and change its font colour
 
Join Date: Aug 2022
Posts: 11
Harvi007 is on a distinguished road
Question Select single word to left of comma and change its font colour

Good Evening All,

I have a question that I hope someone can help me with.

I'd like to perform a find & replace of sorts.



I'd like to find the words directly before commas and change the colour of them in a whole document, e.g.

Original Text:
This is line, number one in word.
This is line number, two in word.
This is line number three in, word.

Desired Result:
This is line, number one in word.
This is line number, two in word.
This is line number three in, word.

I don't mind if the comma also changes colour as it will be removed after.

I've looked around online but couldn't really find anything that would get me started or at least point me in the right direction.

Any help on this would me much appreciated.

Thanks in advance,

Harvi
Reply With Quote
  #2  
Old 03-03-2023, 09:39 PM
gmayor's Avatar
gmayor gmayor is offline Select single word to left of comma and change its font colour Windows 10 Select single word to left of comma and change its font colour Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The following should work for you
Code:
Sub Macro1()
Dim oRng As Range
    Set oRng = ActiveDocument.Range
    With oRng.Find
        Do While .Execute(findText:=",")
            oRng.MoveStartUntil Chr(32), wdBackward
            oRng.Font.ColorIndex = wdRed
            oRng.Collapse 0
        Loop
    End With
    Set oRng = Nothing
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 03-04-2023, 04:16 AM
Harvi007 Harvi007 is offline Select single word to left of comma and change its font colour Windows 11 Select single word to left of comma and change its font colour Office 2019
Novice
Select single word to left of comma and change its font colour
 
Join Date: Aug 2022
Posts: 11
Harvi007 is on a distinguished road
Thumbs up

Hi Gmayor

Thank you for getting back to me.

The code you provided has worked perfectly.

Thank you so much for this, it has helped me a lot in my project.

Take care,
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Marco to change font colour of every other word Harvi007 Word VBA 2 08-05-2022 02:01 PM
Select single word to left of comma and change its font colour Select and change font size of words by number of characters knpaddac Word VBA 3 03-15-2021 03:00 PM
Select single word to left of comma and change its font colour VBA to change font colour in email body on send RealmOfCOnfusion Outlook 1 06-30-2016 09:55 PM
Change single character in PPT to another font macro rtwwpad PowerPoint 1 01-19-2013 05:08 PM
Select single word to left of comma and change its font colour Change font colour when tasks are completed meileetan Project 3 09-12-2012 07:09 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:10 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft