There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Business Applications
Tag Cloud
access acer asus bios bsod computer crash drive driver drivers error ethernet excel freeze games gaming graphics hard drive hardware hdmi internet laptop malware memory monitor motherboard netgear network printer problem ram random registry router slow software sound trojan usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless xbox
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Business Applications >
Solved: Macro Multiple Find and Replace in Excel 2007

Reply  
Thread Tools
Lynchie's Avatar
Junior Member with 3 posts.
 
Join Date: Sep 2009
Experience: Beginner
09-Sep-2009, 08:14 AM #1
Solved: Macro Multiple Find and Replace in Excel 2007
Hi,

Can someone please help? I need a way to be able to find and replace in Excel on a mass scale. I have three colums A, B, C. I want to be able to find the value from Column A and replace it with the value in the same row in column B wherever it appears in Column C

Column A ********Column B ******** Column C
Cat ************Dog************* www.lynchie.com/cat/UK
etc etc**************************www.lynchie.com/horse/uk
*******************************www.lynchie.com/cat/uk
*******************************www.lynchie.com/mouse/uk

(Apologies for the bad rendering of an Excel Sheet)

This is a simple find and replace. However, I have approximately 1,000 pairs in column A and B which need to be found and replaced in Column C (and Column C is 100,000 rows+).


Is there any macro / process which I could use or I'm I doomed to do a find and replace 1,000 times?

Any help / suggestions would be hugely appreciated,

Thanks

Lynchie
terabytecomputer's Avatar
Member with 104 posts.
 
Join Date: Apr 2009
Experience: Hooked since my TI-99/4A
09-Sep-2009, 08:48 AM #2
I'm not sure if you have it worded backwards, or if I'm thinking backwards. What you say you're trying to do doesn't make sense to me.

If you have this:
Column A ********Column B ******** Column C
Cat ************Dog************* www.lynchie.com/cat/UK
Mouse**********Horse************www.lynchie.com/horse/uk
Lion************Cat**************www.lynchie.com/cat/uk
Mouse**********Elephant**********www.lynchie.com/mouse/uk

Do you want to end up with this (what it appears to me you're asking):
Column A ********Column B ******** Column C
Dog ************Dog************* www.lynchie.com/cat/UK
Mouse**********Horse************www.lynchie.com/horse/uk
Lion************Cat**************www.lynchie.com/cat/uk
Elephant**********Elephant**********www.lynchie.com/mouse/uk

Or this (what I think you mean):
Column A ********Column B ******** Column C
Cat ************Cat************* www.lynchie.com/cat/UK
Mouse**********Horse*************www.lynchie.com/horse/uk
Lion************Cat**************www.lynchie.com/cat/uk
Mouse**********Mouse************www.lynchie.com/mouse/uk

or neither?
__________________
If you're not living on the edge, you're taking up too much space!
Lynchie's Avatar
Junior Member with 3 posts.
 
Join Date: Sep 2009
Experience: Beginner
09-Sep-2009, 10:29 AM #3
errr... neither

Apologies - I did not depict this as clearly as I thought. There is no relationship between Column C and the other two columns.

A better way of depicting this would be:

Column A*****Column B
Dog*********Cat
Duck********Horse
Lion*********Fox
Mouse*******Cow

Column C
www.lynchie.com/duck/uk
www.lynchie.com/dog/uk
www.lynchie.com/mouse/uk
www.lynchie.com/lion/uk

Running through. Wherever the term 'dog' appears in Column C I want to replace it with the term 'cat'. Whenever the term 'duck' appears I want to replace it with 'horse'. This means the above would end up as:

Column A*****Column B
Dog*********Cat
Duck********Horse
Lion*********Fox
Mouse*******Cow

Column C
www.lynchie.com/horse/uk
www.lynchie.com/cat/uk
www.lynchie.com/cow/uk
www.lynchie.com/fox/uk

>> terabycomputer - does this make some more sense now?

Best Wishes,

Lynchie
Rollin_Again's Avatar
Senior Member with 4,273 posts.
 
Join Date: Sep 2003
Location: Atlanta, GA - Planet Earth
Experience: Brilliant When Sober
09-Sep-2009, 06:11 PM #4
Here you go. Just replace the portion in red to reflect the correct range of data in column A.

Code:
Sub ReplaceText()

For Each vCell In Range("A2:A100").Cells

Columns("C:C").Cells.Replace What:=vCell, Replacement:=vCell.Offset(0, 1).Value, LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False

Next vCell

End Sub
Regards,
Rollin
Lynchie's Avatar
Junior Member with 3 posts.
 
Join Date: Sep 2009
Experience: Beginner
11-Sep-2009, 08:07 AM #5
Thanks Rollin - works like a dream!

Best Wishes,

Lynchie
DMR1712's Avatar
Computer Specs
Junior Member with 2 posts.
 
Join Date: Sep 2009
Experience: Beginner
24-Sep-2009, 12:53 PM #6
This is exactly what I was looking for, thank you very, very much!

I however have another problem, My column A consists of entries that are formatted like this:

Example 1--------replace by "one"
Example 2--------replace by "two"
etc
Example 10-------replace by "ten"
etc
etc into the hundreds

Maybe you already see my problem, Changing Example 1 ofcourse also changes Example 10. This then becomes "one0" instead of "ten"

Is there a possibility to circumvent this? Maybe reverse the process (instead of top to bottom, bottom to top)?

Thanks in advance for your help.

Best,
DMR1712
Rollin_Again's Avatar
Senior Member with 4,273 posts.
 
Join Date: Sep 2003
Location: Atlanta, GA - Planet Earth
Experience: Brilliant When Sober
24-Sep-2009, 02:21 PM #7
Change the portion of the code that is highlighted in red so that is reads xlWhole

Quote:
Columns("C:C").Cells.Replace What:=Range("A" & i).Value, Replacement:=Range("A" & i).Offset(0, 1).Value, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
I've also included macro code that will search from the bottom up. Just change the values in red to reflect your correct start and end rows.

Code:
Sub ReplaceString()

StartRow = 1
EndRow = 10

For i = EndRow To StartRow Step -1

Columns("C:C").Cells.Replace What:=Range("A" & i).Value, Replacement:=Range("A" & i).Offset(0, 1).Value, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

Next i

End Sub



Regards,
Rollin

Last edited by Rollin_Again; 24-Sep-2009 at 02:42 PM..
DMR1712's Avatar
Computer Specs
Junior Member with 2 posts.
 
Join Date: Sep 2009
Experience: Beginner
25-Sep-2009, 07:06 AM #8
Brilliant! this worked like a charm!

thank you so much!
Reply

Tags
excel, excel 2007, find and replace, macro

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 03:34 PM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.