Solved

Automate Excel value change

Posted on 2011-02-15
8
177 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
Industry Leaders: 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!

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

749 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