Solved

Automate Excel value change

Posted on 2011-02-15
8
174 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
  • 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
 

Author Comment

by:russell_chance
ID: 34898916
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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 code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now