Solved

Excel VBA Script to find a cell and replace a different cell with a value.

Posted on 2016-08-11
3
48 Views
Last Modified: 2016-08-11
Hi Experts

I am in need of some help with a VBA script please.  I have a single workbook with a tab labeled "final".  

First thing I need to do is in Column "D" find two different values 123 and 456.  There will be no dupes and these are unique to that
column.  Find each of the values and change whatever value is in Column F (of the same row as the column D value) to 30-03-01.

Second thing on this same tab.  In column D find "BB1224" and whatever value is in column I of the same row subtract 30.  

Any help would be so greatly appreciated.

Andy
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
  • 2
3 Comments
 
LVL 31

Accepted Solution

by:
Subodh Tiwari (Neeraj) earned 500 total points
ID: 41752891
You may try something like this.....
Const val1 As Integer = 123
Const val2 As Integer = 456
Const val3 As String = "BB1224"

Sub FindAndReplaceValues()
Dim ws As Worksheet
Dim rng1 As Range, rng2 As Range, rng3 As Range

Set ws = Sheets("final")

Set rng1 = ws.Range("D:D").Find(what:=val1, LookIn:=xlValues, lookat:=xlWhole)
If Not rng1 Is Nothing Then
    ws.Cells(rng1.Row, "F") = "30-03-01"
End If
Set rng2 = ws.Range("D:D").Find(what:=val2, LookIn:=xlValues, lookat:=xlWhole)
If Not rng2 Is Nothing Then
    ws.Cells(rng2.Row, "F") = "30-03-01"
End If
Set rng3 = ws.Range("D:D").Find(what:=val3, LookIn:=xlValues, lookat:=xlWhole)
If Not rng2 Is Nothing Then
    ws.Cells(rng3.Row, "I") = ws.Cells(rng3.Row, "I") - 30
End If
End Sub

Open in new window

0
 

Author Closing Comment

by:spudmcc
ID: 41752933
Thank you for your quick response.  This works perfectly.  

I so much appreciate you sharing your time and knowledge.  

A
0
 
LVL 31

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41752938
You're welcome. Glad I could help.
Thanks for the feedback.
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

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…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

752 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