I discovered a mistake in the formula in over 700 spreadsheets. I came up with the following code to traverse the folders and put it into a spreadsheet, but I am unsure how to open each file, change the formula and insert a lookup range, save the file and close it before going on to the next file.
I get to the line Range("M49").Formula and it gives me a runtime error 1004. I tried to active the file's worksheet but that gave me another error.
Any suggestions would be appreciated as this would save me many hours.
Thanks
---------------------------------------------------------
Set fs = Application.FileSearch
With fs
.LookIn = "G:\cmills\Excel\Daily Planners" ' All the files are under the Dir
.Filename = "Daily Planner *.xls" ' All the files begin with this
.SearchSubFolders = True
If .Execute > 0 Then
' MsgBox "There were " & .FoundFiles.Count & _
' " file(s) found."
DP_Row = 2
For i = 1 To .FoundFiles.Count ' For every file found do this
Filename = .FoundFiles(i)
Open Filename For Random As 1
Range("M49").Formula = _
"=IF(ISBLANK(N49),L49-K49-VLOOKUP('1/2 hour lunch',N61:O64,2,FALSE),L49-K49-VLOOKUP(N49,N61:O64,2,FALSE))"
Range("N61").Value = "1 hour lunch"
Range("O61").Value = 0.0415
Range("N62").Value = "1/2 hour lunch"
Range("O62").Value = 0.0205
Range("N63").Value = "3/4 hour lunch"
Range("O63").Value = 0.031
Range("N64").Value = "No lunch"
Range("O64").Value = 0
Filename.Save
Close 1
DP_Row = DP_Row + 1
' MsgBox .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
End With
I get to the line Range("M49").Formula and it gives me a runtime error 1004. I tried to active the file's worksheet but that gave me another error.
Any suggestions would be appreciated as this would save me many hours.
Thanks
---------------------------------------------------------
Set fs = Application.FileSearch
With fs
.LookIn = "G:\cmills\Excel\Daily Planners" ' All the files are under the Dir
.Filename = "Daily Planner *.xls" ' All the files begin with this
.SearchSubFolders = True
If .Execute > 0 Then
' MsgBox "There were " & .FoundFiles.Count & _
' " file(s) found."
DP_Row = 2
For i = 1 To .FoundFiles.Count ' For every file found do this
Filename = .FoundFiles(i)
Open Filename For Random As 1
Range("M49").Formula = _
"=IF(ISBLANK(N49),L49-K49-VLOOKUP('1/2 hour lunch',N61:O64,2,FALSE),L49-K49-VLOOKUP(N49,N61:O64,2,FALSE))"
Range("N61").Value = "1 hour lunch"
Range("O61").Value = 0.0415
Range("N62").Value = "1/2 hour lunch"
Range("O62").Value = 0.0205
Range("N63").Value = "3/4 hour lunch"
Range("O63").Value = 0.031
Range("N64").Value = "No lunch"
Range("O64").Value = 0
Filename.Save
Close 1
DP_Row = DP_Row + 1
' MsgBox .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
End With