Solved

Automate Excel value change

Posted on 2011-02-15
8
178 Views
Last Modified: 2012-06-21
I have about 1000 spread sheets that i need to change a value in. I need to find a value in cell A (for example lets say cell A12) and replace the value in cell C12. Cell A is an item number and cell C is the price. So basically I need to change the price of item number xxxxxxxx, in 1000 spreadsheets. Would a VBA script be the most logical solution to make this change on all the worksheets? Can anyone give me some suggestions on how to create a VBA script that will accomplish this task?
0
Comment
Question by:russell_chance
[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
  • 6
  • 2
8 Comments
 
LVL 24

Expert Comment

by:StephenJR
ID: 34897584
First, why have you got a 1000 spreadsheets? That sounds as if there should be better solutions.

You could do Find and Replace, though no doubt would take some time.
0
 

Author Comment

by:russell_chance
ID: 34898278
We have a different spreadsheet for each different standard. The value is not difficult to locate because each spreadsheet is only 47 lines long. Find and Replace wouldn't serve much purpose. It would take an exhorbitant amout of time to chagne them all manually and other values may need to be changed in the future.  
0
 
LVL 24

Expert Comment

by:StephenJR
ID: 34898381
Post a workbook.
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

Author Comment

by:russell_chance
ID: 34898916
0
 

Author Comment

by:russell_chance
ID: 34898965
In the example I posted, lets say I want the OPG to be 1.2760 (cell D12) instead of 1.9430. Cell D12 is related to cell A12. Everywhere the item number of 00550014 is located, the OPG on the same row should be change to the new value of 1.2760.
0
 

Accepted Solution

by:
russell_chance earned 0 total points
ID: 34906262
I found a solution.

Please notice config area ie. Call FindReplaceFilesInPath("Sheet1", "C:\test", "qwerty", 1, 3, 45.68)

In order these are:
Sheet to look at/Search
Full Path to the Directory to Search
Word to Search For
The Column to search i.e. 1 = ColA
The Column To replace value in i.e 3 = ColC
the Value to replace with i.e. new value to put in column C


Code:

------------------------------------------------------------------------------------------------------------------------------------------------

Option Compare Text

Public Sub SubmitParametersOfFindReplace()

   'Configuration Here VVVVVV
   Call FindReplaceFilesInPath("Sheet1", "C:\test", "qwerty", 1, 3, 45.68)
   
End Sub

Private Sub FindReplaceFilesInPath(SheetName As String, Path As String, _
ValueToFind As String, FindCol As Integer, ChangeCol As Integer, NewPrice As Currency)

    Dim fs, f, f1, fc, s
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFolder(Path)
    Set fc = f.Files
   
    Dim TargBk As Workbook
    Dim LogSh As Worksheet
    Dim BkNameCol As Integer
    Dim StatusCol As Integer
    Dim LogRow As Integer
    BkNameCol = 1
    StatusCol = 2
    LogRow = 1
   
    ' Create Log sheet
    ThisWorkbook.Sheets.Add before:=ActiveSheet
    Set LogSh = ThisWorkbook.ActiveSheet
   
    'Loop thru all books in Dir
    For Each f1 In fc
        LogRow = LogRow + 1
       ' Check FileName meets criteria
       If Right(f1.Name, 3) = "xls" And IsNumeric(Left(f1.Name, 3)) Then
          ' Open book
           Workbooks.Open Filename:=f1.Path
           Set TargBk = ActiveWorkbook
          ' Search Sheet
          With TargBk.Worksheets(SheetName).Cells(1, FindCol).EntireColumn
             Set c = .Find(ValueToFind, LookIn:=xlValues, lookat:=xlWhole)
             If c Is Nothing Then
                With LogSh
                   .Cells(LogRow, BkNameCol).Value = f1.Name
                   .Cells(LogRow, StatusCol).Value = ValueToFind & " Not Found"
                 End With
             Else
                 ActiveWorkbook.Worksheets(SheetName).Cells(c.Row, ChangeCol).Value = NewPrice
                 With LogSh
                   .Cells(LogRow, BkNameCol).Value = f1.Name
                   .Cells(LogRow, StatusCol).Value = "Updated row (" & c.Row & ")"
                 End With
             End If
             
              ' Close book
              TargBk.Close SaveChanges:=True
          End With 'TargBook
      Else ' Right(f2.Name
         With LogSh
            .Cells(LogRow, BkNameCol).Value = f1.Name
            .Cells(LogRow, StatusCol).Value = "Invalid Book Name"
         End With
      End If ' Right(f2.Name
     
     
    Next f1
   
    msg = "Logged Results on " & LogSh.Name
    pt = MsgBox(msg, vbInformation, "Process Complete")
   
End Sub
0
 

Author Comment

by:russell_chance
ID: 34927192
Does this mean I get my points back?
0
 

Author Closing Comment

by:russell_chance
ID: 34941282
Someone from another website (excelforum.com) created this code for me. I tested it out and it works.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

734 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