Avatar of spudmcc
spudmcc
Flag for United States of America asked on

Find value in one column and replace value in another

Hi Experts

I am having trouble finding a solution to my task so I am once again hoping that I might get some assistance here.  
I require a VBA script to find the values listed in Column D and replace whatever is currently in Column F with the value "30-03-AM".  
The sheet name is constant "COMBINATION-DLY" and the columns that the data will appear in is always the same.  What changes
from day to day is the row that the data appears.  It varies from day to day based on the total number of records.  Also there is a chance that a value may NOT be there every day.  

Any help would be greatly appreciated.  

Andy

Column D      Column F
252881            30-03-AM
252889            30-03-AM
252890            30-03-AM
207554            30-03-AM
233230            30-03-AM
252844            30-03-AM
253279            30-03-AM
257168            30-03-AM
261858            30-03-AM
Microsoft Excel

Avatar of undefined
Last Comment
Subodh Tiwari (Neeraj)

8/22/2022 - Mon
Subodh Tiwari (Neeraj)

Please try this....
Sub ReplaceValues()
Dim lr As Long
Dim rng As Range
lr = Cells(Rows.Count, 4).End(xlUp).Row
ActiveSheet.AutoFilterMode = 0
With Range("D1:D" & lr)
   .AutoFilter field:=1, Criteria1:="<>"
   On Error Resume Next
   Set rng = Range("F2:F" & lr).SpecialCells(xlCellTypeVisible)
   If Not rng Is Nothing Then rng.Value = "30-03-AM"
End With
ActiveSheet.AutoFilterMode = 0
End Sub

Open in new window

spudmcc

ASKER
Not sure if I it was clear that there are other values in both columns.  I can't do a global type find and replace.  It must be where the specific value in column D (one of those listed) is found and then the replacement can be done.  Column D might contains thousands of other values.  I am sorry I wasn't more clear.  

A
Subodh Tiwari (Neeraj)

Where are those criteria for col. D placed in the workbook, on another Sheet?
Or you want to use them as hard coded values in the code?

Can you upload a sample workbook with some dummy data to work with?
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER CERTIFIED SOLUTION
Subodh Tiwari (Neeraj)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
spudmcc

ASKER
You are fantastic.  This is exactly what I needed to complete this project.  Thank you for your prompt response and sharing your knowledge.  

Andy
Subodh Tiwari (Neeraj)

You're welcome Andy! Glad to help.