If False Do Nothing

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

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
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,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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