EXCEL MACRO - Find and replace looping on rows

snowcrash

New Member
Joined
Mar 1, 2018
Messages
10
Hi All,
My first post. I am new to VBA, and just learning.
I have find and replace complication which i am struggling to solve with a looping logic.

I have Data in column A, I then want to find and replace a certain part of a url in in the same row G:WV this certain part to find is referenced in cell F1 "REPLACE" throughout the entire worksheet

the replace data input in column A is distinctive for each row, and I need the macro to keep going to the next row and the next doing the same logical find replace until there are no more rows

I currently have this which only performs the task on one specified row, F1 is same for every row in the worksheet.

Range("G3:WV3").Select
Selection.Replace What:=Range("f1").Value, Replacement:=Range("A3").Value, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Could you not just use find and replace on the spreadsheet itself, probably quicker, if this is something you are likely to do often then record the macro as you do it to see the steps taken, you should not really have to loop to achieve this.
 
Last edited:
Upvote 0
The input is different for each row. e.g. row 3 input data CELL A3 = "input1" , row 4 input data Cell A4 = "input2" no two rows have the same replace with data, so the find and replace manual option is time consuming as i will end up with other 1000 rows to perform this task.

i tired the record macro option but i wasn't useful to me here unfortunately.
 
Upvote 0
You said F1 was the same for every row in the worksheet.

where is the identifying cell for each row then
 
Upvote 0
F1 = find what
column A = Replace with
update range G:WV

F1 is fixed for all rows
A is specif for each row e.g.
A3 = replace with , update range G3:WV3
A4 = replace with , update range G4:WV4
A5 = replace with , update range G5:WV5

Keep looping this until no more data in column A, this can go beyond 1000 rows
 
Upvote 0
assuming your code worked I have put it into a loop

Code:
Sub KWChangeWord()


Dim Lastrow As Long
Dim i As Long


Lastrow = Cells(Rows.Count, 1).End(xlUp).Row
i = 3


For i = 3 To Lastrow
    ActiveSheet.Cells(i, 7).Resize(1, 614).Select
     Selection.Replace What:=Range("f1").Value, Replacement:=Cells(i, 1).Value, LookAt:=xlPart, _
    SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    ReplaceFormat:=False
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,235
Messages
6,123,782
Members
449,123
Latest member
StorageQueen24

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