Lori, what is the naming convention of the file and where is it located. For example, is the file for store #2 called "C:\2.xls"?
BarrieBarrie Davidson
Barrie,
Here is example; the file for store 2 is C:\Cube Analysis\Store2.xls
Lori
Lori, here is the code changed to automatically update the files. Please note that I have turned screen updating off for the macro (to speed it up) so you won't see anything happening while the macro is running. At the end of the macro you will receive a message box stating "Copying complete". Test it out (on sample files) and let me know how it works out for you.
Sub Data_Copy_To_File()
' Written by Barrie Davidson
Dim searchValue
Dim searchValueAddress As String
Dim dataFile As String
Dim newFile As String
Application.ScreenUpdating = False
dataFile = ActiveWorkbook.Name
Range("A1", Range("A1").End(xlDown).Address).AdvancedFilter _
Action:=xlFilterCopy, CopyToRange:=Range( _
"E1"), Unique:=True
searchValueAddress = "E2"
searchValue = Range("E2").Value
Do Until searchValue = ""
Selection.AutoFilter
Range("A1", Range("C1").End(xlDown).Address).Select
Selection.AutoFilter Field:=1, Criteria1:=searchValue
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Workbooks.Open FileName:="C:\Cube Analysis\Store" & searchValue & ".xls"
If Range("A1").Value <> "" Then
Range("A1").End(xlDown).Offset(1, 0).Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveCell.EntireRow.Delete
Else
ActiveSheet.Paste
Application.CutCopyMode = False
End If
Range("A1").Select
ActiveWorkbook.Close (True)
Windows(dataFile).Activate
searchValueAddress = Range(searchValueAddress).Offset(1, 0).Address
searchValue = Range(searchValueAddress).Value
Loop
Range("A1", Range("C1").End(xlDown).Address).AutoFilter
Range("E1", searchValueAddress).ClearContents
Application.ScreenUpdating = True
Range("A1").Select
MsgBox ("Copying complete")
End Sub
Regards,
BarrieBarrie Davidson
Barrie,
Thank you
Thank you
Thank you!!!
This works great!
Lori