Select and Replace help needed

igrock

New Member
Joined
Oct 27, 2011
Messages
2
Hi everyone

I need help with the below macro. The first part of the macro selects and copies to clipboard 15 cells in one worksheet then pastes them into another worksheet, finds the value "888" and replaces it with the value "999". Then the second part part of the macro repeats the process from pasting 15 cells starting from row 16.
I don't have a problem with the first value "888" because it is static and does not change but the second value "999" has to be pulled from another worksheet each time from the next cell down -- A1, A2, A3, etc. And this needs to be on a loop until there is no more values in the A column.

Does anyone know how to do this? Thanks for your help!




Sheets("Sheet1").Select
Selection.Copy
Sheets("Sheet2").Select
ActiveSheet.Paste
Selection.Replace What:="888", Replacement:="999", LookAt:=xlPart, _
SearchOrder:=xlByColumns, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
ActiveCell.Offset(15, 0).Range("A1").Select
ActiveSheet.Paste
Selection.Replace What:="888", Replacement:="999", LookAt:=xlPart, _
SearchOrder:=xlByColumns, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Welcome to MrExcel.

Assuming that Sheet3 is the name of the worksheet that contains the replacement try the untested:

Code:
    Sheets("Sheet1").Select
    Selection.Copy
    Sheets("Sheet2").Select
    ActiveSheet.Paste
    Selection.Replace What:="888", Replacement:="999", LookAt:=xlPart, _
        SearchOrder:=xlByColumns, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    Dim LastRow As Long
    Dim r As Long
    With Worksheets("Sheet3")
        LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
        For r = 2 To LastRow
            ActiveCell.Offset(15, 0).Range("A1").Select
            ActiveSheet.Paste
            Selection.Replace What:="888", Replacement:=.Range("A" & r).Value, LookAt:=xlPart, _
                SearchOrder:=xlByColumns, MatchCase:=False, SearchFormat:=False, _
                ReplaceFormat:=False
        Next r
    End With
 
Upvote 0
sorry, i edited my post as I answered the same question but didn't see you post until after. I should have been more clear :D
 
Upvote 0
Thank you, Andrew!!! you are a genius. Deleted the first unnecessary part, edited the names of the sheet and it works like a dream. Thank you!


Welcome to MrExcel.

Assuming that Sheet3 is the name of the worksheet that contains the replacement try the untested:

Code:
    Sheets("Sheet1").Select
    Selection.Copy
    Sheets("Sheet2").Select
    ActiveSheet.Paste
    Selection.Replace What:="888", Replacement:="999", LookAt:=xlPart, _
        SearchOrder:=xlByColumns, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    Dim LastRow As Long
    Dim r As Long
    With Worksheets("Sheet3")
        LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
        For r = 2 To LastRow
            ActiveCell.Offset(15, 0).Range("A1").Select
            ActiveSheet.Paste
            Selection.Replace What:="888", Replacement:=.Range("A" & r).Value, LookAt:=xlPart, _
                SearchOrder:=xlByColumns, MatchCase:=False, SearchFormat:=False, _
                ReplaceFormat:=False
        Next r
    End With
 
Upvote 0

Forum statistics

Threads
1,225,071
Messages
6,182,694
Members
453,132
Latest member
nsnodgrass73

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