Quantcast
Channel: Excel IT Pro Discussions forum
Viewing all articles
Browse latest Browse all 11829

Search & Replace Macro

$
0
0
Hi All,

Not sure if anyone can help me with this but I have the following DataSet:



Column A and B go on for about 11,765 lines. Column D and E go on for 605 lines. 

I recorded a Macro that will copy the data in Cell D2, Search for it in Column A and then replace the number in Coulmn B with the number from Coulmn E. In the example it searches for number "10000027" in Column A and it is found in Cell A28. It then takes the number from E2 and replaces it with the Number in Cell B28. It then moves onto the next number which is "10000037" and follows the same process. 

I then looked at the code and got the following:

[CODE]Sub SearchReplace()
'
' SearchReplace Macro
'
'
    Range("D2").Select
    Selection.Copy
    Columns("A:A").Select
    Selection.Find(What:="10000027", After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate
    Range("E2").Select
    Application.CutCopyMode = False
    Selection.Copy
    Range("B28").Select
    ActiveSheet.Paste
    Range("D3").Select
    Application.CutCopyMode = False
    Selection.Copy
    Columns("A:A").Select
    Selection.Find(What:="10000037", After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate
    Range("E3").Select
    Application.CutCopyMode = False
    Selection.Copy
    Range("B38").Select
    ActiveSheet.Paste
    Range("D4").Select
    Application.CutCopyMode = False
    Selection.Copy
    Columns("A:A").Select
    Selection.Find(What:="10000043", After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate
    Range("E4").Select
    Application.CutCopyMode = False
    Selection.Copy
    Range("B44").Select
    ActiveSheet.Paste
    Range("D5").Select
End Sub
[/CODE]

Can anyone help adjust it so that it steps through the whole document one by one, rather than having to manually record the macro and do it manually one by one? 

Many thanks for the help



Viewing all articles
Browse latest Browse all 11829

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>