find and replaced macro

kylefoley76

Well-known Member
Joined
Mar 1, 2010
Messages
1,553
I'm going to convert a lot of words in a cell into numbers, maybe about 300. So I need to build a macro that can find and replace a lot of words. I only want it to apply to one column.
 
I don't see why there are two subroutines. when i run the first macro it pulls up a box and i guess i'm supposed to select callfindreplace. i did and nothing happened. i tried running the callfindreplace without the first macro and it didn't work either.
 
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Copy both the sub in a same module and Call callfindreplace Macro it will allow you to set at which sheet what you want to replace.
 
Upvote 0
I don't understand what you mean. I have the two subs in one module. I run the first sub and it does not allow me to set at which sheet I want to replace.
 
Upvote 0
1:Copy both sub in a single module
2: change sub callfindreplace as public sub callfindreplace
3: Press ALT +F11 and select callfindreplace
4: Now Place the cursor any where in callfindreplace sub and then Press Green Button or run the macro



In callfindreplace there are two lines

FindReplace "sheet2", "Exist", "2", 1
it is actually taking 4 parameter
first is your sheet name,
second is Word that has to search
third is word that will be replce the searched text
and
fourth is the column in which find and replace has to implement.


By adding same such line you can find and replace multiple text in multiple column

Thats it

Hope this may make some sens to you






4
 
Upvote 0
ok, thanks . it was working on another workbook which i didn't know about. but i've solved the problem now.
 
Upvote 0
I can't get this to work anymore. I try to make changes to the macro but when I did it stopped working

Code:
Public Sub FindReplace(strSheetName As String, strSrch As String, strReplace As String, lngCol)




    With ThisWorkbook.Worksheets(strSheetName)
        .UsedRange.Columns(lngCol).Replace strSrch, strReplace, xlWhole
    End With
    
End Sub




'In this sub just pass the number of the search and replace  text
Public Sub callFindReplace()






FindReplace "Sheet9", "have", "1", 10
FindReplace "Sheet9", "and", "2", 10
FindReplace "Sheet9", "not", "3", 10
FindReplace "Sheet9", "in", "4", 10
FindReplace "Sheet9", "after", "5", 10


    
End Sub

Here's the workbook I'm using.

https://docs.google.com/file/d/0B9zzW6-3m2qGZERGZjNGUXJLMlk/edit?usp=sharing
 
Upvote 0
Code:
Public Sub FindReplace(strSheetName As String, strSrch As String, strReplace As String, strCol As String)
    With ThisWorkbook.Worksheets(strSheetName)
        .Columns(strCol).Replace strSrch, strReplace, xlWhole
    End With
    
End Sub




'In this sub just pass the number of the search and replace  text
Public Sub callFindReplace()


    FindReplace "sheet9", "Have", "2", "J"
    FindReplace "sheet9", "Not", "3", "J"
    FindReplace "sheet9", "And", "3", "J"
    
End Sub

Just Pass the Column Header as a last parameter and for example i have Passed j as it is the column in wich you have to implement find and replace.
 
Upvote 0

Forum statistics

Threads
1,216,076
Messages
6,128,670
Members
449,463
Latest member
Jojomen56

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top