Solved

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

Posted on 2016-08-11
3
36 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
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 28

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
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…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
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…

932 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

12 Experts available now in Live!

Get 1:1 Help Now