• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

Automate Excel value change

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
russell_chance
Asked:
russell_chance
  • 6
  • 2
1 Solution
 
StephenJRCommented:
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
 
russell_chanceAuthor Commented:
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
 
StephenJRCommented:
Post a workbook.
0
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!

 
russell_chanceAuthor Commented:
0
 
russell_chanceAuthor Commented:
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
 
russell_chanceAuthor Commented:
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
 
russell_chanceAuthor Commented:
Does this mean I get my points back?
0
 
russell_chanceAuthor Commented:
Someone from another website (excelforum.com) created this code for me. I tested it out and it works.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now