Solved

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

Posted on 2016-08-11
3
40 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 29

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 29

Expert Comment

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

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

777 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