Winchester1894

New Member
Joined
Jan 20, 2018
Messages
2
How do you do Friends,

I have a large data set and I would like to search for a keyword and update the cell 5 columns over from it.
This is what I have so far:

Code:
Sub Find_and_Write()

Dim X As Variant, F As Range
X = Application.InputBox("Enter Value")
If TypeName(X) = "Boolean" Then Exit Sub
Set F = Columns("C").Find(what:="C-1290", LookIn:=xlValues, lookat:=xlWhole)
If Not F Is Nothing Then F.Offset(, 5).Value = X


End Sub

This code works but only for the first instance of the desired change. I would like it to run down the entire column and perform the edit. I tried adding a for loop but it only looped changing the first instance. What am I missing to make it run for the entirety of the column?

Any help appreciated, thank you.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hello Winchester1894,

Here is the updated code...
Code:
Sub Find_and_Write()


    Dim F           As Range
    Dim FirstFind   As String
    Dim X           As Variant


        X = Application.InputBox("Enter Value")
        If TypeName(X) = "Boolean" Then Exit Sub
        
        Set F = Columns("C").Find(what:="C-1290", LookIn:=xlValues, lookat:=xlWhole)
        If F Is Nothing Then Exit Sub
        
        FirstFind = F.Address
        
        Do
            F.Offset(0, 5) = X
            Set F = Columns("C").FindNext(F)
            If F Is Nothing Then Exit Do
            If F.Address = FirstFind Then Exit Do
        Loop


End Sub
 
Upvote 0
Hi & welcome to the board
Another option
Code:
Sub Find_and_Write()

Dim X As Variant
X = Application.InputBox("Enter Value")
If TypeName(X) = "Boolean" Or Len(X) = 0 Then Exit Sub
With Range("H2", Range("C" & Rows.Count).End(xlUp).Offset(, 5))
   .Value = Evaluate("if(" & .Offset(, -5).Address & "=""AL2 2EJ""," & Chr(34) & X & Chr(34) & "," & .Address & ")")
End With

End Sub
 
Last edited:
Upvote 0
Hello Winchester1894,

You are most welcome. Glad I could be of assistance.
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,192
Members
449,072
Latest member
DW Draft

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