[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Find value in one column and replace value in another

Posted on 2016-08-31
6
Medium Priority
?
81 Views
Last Modified: 2016-08-31
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
0
Comment
Question by:spudmcc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 33

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41778438
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

0
 

Author Comment

by:spudmcc
ID: 41778464
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
0
 
LVL 33

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41778470
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?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 33

Accepted Solution

by:
Subodh Tiwari (Neeraj) earned 2000 total points
ID: 41778548
If you list your criteria for column D on a separate sheet in column A (e.g. in column A on Sheet2 in the attached), then you may use the following code to get the desired output.
Please change the sheet names used in the code as per your requirement.
Sub ReplaceValues()
Dim lr As Long, dlr As Long, i As Long
Dim rng As Range
Dim arrFilters() As String
Application.ScreenUpdating = False
lr = Cells(Rows.Count, 4).End(xlUp).Row
With Worksheets("Sheet2")
   dlr = .Cells(Rows.Count, 1).End(xlUp).Row
   ReDim arrFilters(1 To dlr)
   For i = 1 To dlr
      arrFilters(i) = CStr(.Range("A" & i).Value)
   Next i
End With
ActiveSheet.AutoFilterMode = 0
With Worksheets("Sheet1").Range("A1").CurrentRegion
   .AutoFilter field:=4, Criteria1:=arrFilters, Operator:=7
   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
Application.ScreenUpdating = True
End Sub

Open in new window

Click the button "Replace Values" on Sheet1 to run the code.
Replace-Values.xlsm
0
 

Author Closing Comment

by:spudmcc
ID: 41778629
You are fantastic.  This is exactly what I needed to complete this project.  Thank you for your prompt response and sharing your knowledge.  

Andy
0
 
LVL 33

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41778633
You're welcome Andy! Glad to help.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question