Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2016-08-11
3
Medium Priority
?
53 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 33

Accepted Solution

by:
Subodh Tiwari (Neeraj) earned 2000 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 33

Expert Comment

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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
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…

916 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