Solved

Excel Substitute or Find and Replace or Macro Solution

Posted on 2011-09-06
5
224 Views
Last Modified: 2012-05-12
I have a rather large spread sheet where I would like to have Excel find specific words in the sheet (among thousands of sentences) and replace them with my chosen words.  I use the Substitute Function but it only has up to 8 words I can substitute (find and replace) – I would like to have the ability to seek and replace 20-50 words at a time.   I am trying to figure out a way I can run this in a macro (or other solution).  
Book2.xlsx
0
Comment
Question by:mmmcdee
  • 3
  • 2
5 Comments
 
LVL 24

Expert Comment

by:StephenJR
ID: 36491420
Well code could loop through a series of words, or regular expressions perhaps. Are all the words being replaced by the same word or different ones?
0
 

Author Comment

by:mmmcdee
ID: 36491443
Different Words. Replacing words within sentences.  I created a sample attached sheet.
0
 

Author Comment

by:mmmcdee
ID: 36491527
Correction:  All of the words are being replaced by the same word.
0
 
LVL 24

Accepted Solution

by:
StephenJR earned 500 total points
ID: 36491837
Yes, thank you.
Sub x()

Dim oRgx As Object, rCell As Range, v, w

Set oRgx = CreateObject("VBScript.RegExp")

v = Range("D6:D14")
w = Join(Application.Transpose(v), "|")

With oRgx
    .Global = True
    .Pattern = w
    For Each rCell In Range("B6", Range("B6").End(xlDown))
        rCell.Offset(, 5) = .Replace(rCell, Range("D4").Value)
    Next rCell
End With

End Sub

Open in new window

0
 

Author Closing Comment

by:mmmcdee
ID: 36492345
Awesome Job
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now