VBA for find and replace loop

butters149

New Member
Joined
Mar 21, 2018
Messages
23
Hey everyone,

My first post here and I am also fairly new to VBA but I've been having some minor success with just trial and error. My most frustrating struggle so far is the loop function. Below is the function I am trying to do. Basically I want to search for Collector, move to the cell next to it which is blank and add a #. I have to do this because my other vba macro will stop selection if it see a blank cell. I want to find all Collector and then replace the blank cell next to it with a #.

Sub Macro20()
'
' Macro20 Macro
'
' Keyboard Shortcut: Ctrl+g
'
Do
Cells.Find(What:="Collector", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=True, SearchFormat:=False).Activate
ActiveCell.Offset(0, -1).Select
ActiveCell.FormulaR1C1 = "#"
If Not foundCell Is Nothing Then
Exit Do
Loop


End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
What column will we be looking in for "Collector"
Tell me column A or B or something like that
 
Upvote 0
Assuming we will be search column A try this:

If some other column Change the A you see in 3 places to the proper column.

Code:
Sub Test()
'Modified 3-21-18 7:40 PM EDT
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
    For i = 1 To Lastrow
        If Cells(i, "A").Value = "Collector" Then Cells(i, "A").Offset(, 1).Value = "#"
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Well then try this searching column B
Code:
Sub Test()
'Modified 3-21-18 7:40 PM EDT
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "B").End(xlUp).Row
    For i = 1 To Lastrow
        If Cells(i, "B").Value = "Collector" Then Cells(i, "B").Offset(, -1).Value = "#"
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thank-you! This worked =)

Assuming we will be search column A try this:

If some other column Change the A you see in 3 places to the proper column.

Code:
Sub Test()
'Modified 3-21-18 7:40 PM EDT
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
    For i = 1 To Lastrow
        If Cells(i, "A").Value = "Collector" Then Cells(i, "A").Offset(, 1).Value = "#"
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,071
Latest member
cdnMech

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