greg.begin
Member
I have this code here that works when i go through the debugger and then when i run the macro it doesn't work. I have removed some titles for sensitive reasons, but the structure is intact.
Please help.
Code:
Sub Disseminate()
Dim RefName As String
Dim RefDate As String
Dim Names As Integer
Dim I As Integer
Dim rRows As Integer
Dim fName As String
Dim dDate As String
Dim tRows As Integer
Application.ScreenUpdating = False
rRows = WorksheetFunction.CountA(Sheets("etc").Range("a1:a500")) + 3
Names = Sheets("sheet2").Columns.CurrentRegion.Rows.Count - 1
For I = 1 To Names
RefName = Sheets("sheet2").Range("a" & I + 1).Value
RefDate = Range("f1").Value
ActiveSheet.Range("$A$3:$AE$" & rRows).AutoFilter Field:=1, Criteria1:=RefName
If Dir("Some Directory\" & RefName & ".xlsm") <> "" Then
Workbooks.Open Filename:= _
"("Some Directory\" & RefName & ".xlsm", ReadOnly:=False
Workbooks(RefName & ".xlsm").Activate
On Error Resume Next
Sheets(RefDate).Delete
'This is where the code seems to stop
Worksheets.Add().Name = RefDate
Sheets(RefDate).Select
Else
ActiveWorkbook.SaveAs Filename:= _
"("Some Directory\" & RefName & ".xlsm", FileFormat _
:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
Worksheets.Add().Name = RefDate
End If
Windows("Main Sheet.xlsm").Activate
Range("A1").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.Copy
Windows(RefName & ".xlsm").Activate
Range("a1").PasteSpecial Paste:=xlPasteFormulasAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Range("a1").PasteSpecial Paste:=xlPasteComments
Workbooks(RefName & ".xlsm").Worksheets(RefDate).Cells.EntireColumn.AutoFit
tRows = WorksheetFunction.CountA(Range("a3:a10000"))
ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$3:$AF$" & tRows), , xlYes).Name = _
"Table1"
Rows("1:2").Delete Shift:=xlUp
ActiveSheet.ListObjects("Table1").TableStyle = ""
ActiveWorkbook.Close savechanges:=True
Next I
ActiveSheet.Range("$A$3:$AE$" & rRows).AutoFilter Field:=1
dDate = Format([today()], "MM-DD-YYYY")
fName = "Main sheet "
fName = fName & dDate
ActiveWorkbook.SaveAs Filename:= _
"("Some Directory\" & fName _
, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
ActiveWorkbook.Close savechanges:=False
Application.ScreenUpdating = True
End Sub
Please help.