Solved

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

Posted on 2016-08-11
3
31 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
  • 2
3 Comments
 
LVL 28

Accepted Solution

by:
Subodh Tiwari (Neeraj) earned 500 total points
Comment Utility
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
Comment Utility
Thank you for your quick response.  This works perfectly.  

I so much appreciate you sharing your time and knowledge.  

A
0
 
LVL 28

Expert Comment

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

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

What is a Form List Box? (skip if you know this) The forms List Box is the alternative to the ActiveX list box. If you are using excel 2007, you first make sure you have a developer tab (click the Orb)->"Excel Options"->Popular->"Show Developer tab…
Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now