postelrich
New Member
- Joined
- Feb 24, 2011
- Messages
- 31
Hi, I have one master file where I need to split out and send data 15 different regions. I've tried make a macro to automate it by using autofilter and copy to achieve it but I keep getting a Run time Error 1004. I am using Excel 2007, my code below though I cut out the values for the string array. If I step into the code, the error pops up when I get to the copy line.
Code:
Sub SplitFile()
Dim regions(15) As String
regions(0) = "FLORIDA"
For N = LBound(regions) To UBound(regions)
Set wb = Workbooks.Add
With ThisWorkbook.Sheets("MASTER")
.Activate
.AutoFilterMode = False
.Range("C:BY").AutoFilter
.Range("C:BY").AutoFilter Field:=3, Criteria:=regions(N)
.Range("C:BY").SpecialCells(xlCellTypeVisible).Select
.Range("C:BY").Copy
End With
With wb
.Sheet1.Paste
.SaveAs Filename:="C:\Regional Files\" & regions(N)
.Close True
End With
Set wb = Nothing
Next N
End Sub