Hi,
This is going to be a big ask I know but I also know the skills in this forum so I'm confident someone is going to spot the stupid error I've apparently made in here..
The long code I have below fails with the error "Compile error: Next without For" at the highlighted point. Can anyone tell me why?
I've tried to indent the code to show all the If arguments are inside the 2nd For/Next. I expect the problem is having a For/Next inside a For/Next?
Any help would be greatly appreciated.
This is going to be a big ask I know but I also know the skills in this forum so I'm confident someone is going to spot the stupid error I've apparently made in here..
The long code I have below fails with the error "Compile error: Next without For" at the highlighted point. Can anyone tell me why?
Code:
Sub FinalCode()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim x As Long
Dim LR As Long
Dim arr() As Variant
With Sheets("Lookups")
LR = .Cells(.Rows.Count, 13).End(xlUp).Row
arr = .Cells(1, 13).Resize(LR).Value
End With
For x = LBound(arr, 1) To UBound(arr, 1)
Sheets("Lookups").Cells(1, 14).Value = arr(x, 1)
On Error GoTo GetOut
.
.
.
'Code that is all working........
.
.
.
'Generate the report
Dim x1 As Long
Dim LR1 As Long
Dim arr1() As Variant
With Sheets("Lookups")
LR1 = .Cells(.Rows.Count, 1).End(xlUp).Row
arr1 = .Cells(2, 1).Resize(LR - 1).Value
End With
For x1 = LBound(arr1, 1) To UBound(arr1, 1)
Sheets("Signoff").Cells(4, 4).Value = arr(x1, 1)
'Is Report Required?
Sheets("Signoff").Select
If Range("AG5").Value = "Yes" Then
'Filter blank lines out of report
Range("C12:C43").Select
Selection.AutoFilter
ActiveSheet.Range("$C$12:$C$43").AutoFilter Field:=1, Criteria1:="<>"
Range("C12").Select
'Trigger to run outputs
If Range("AG5").Value = "Yes" Then
'Save .xlsm copy
Sheets("Lookups").Activate
If Range("I5") = Yes Then
Sheets("Signoff").Select
ActiveWorkbook.SaveCopyAs Filename:="C:\Dropbox (EP)\846. John Powell\Development\HumanWave\BigTest\excel\" & Range("AB4") & ".xlsm"
Else
End If
'Save as pdf
Sheets("Lookups").Activate
If Range("I8") = Yes Then
Sheets("Signoff").Select
Range("A1:AL45").Select
'Change file directory
Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Dropbox (EP)\846. John Powell\Development\HumanWave\BigTest\pdf\" & Range("AB4") & ".pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False
Range("A1").Select
Else
End If
'Export sheet for collation in master file
Sheets("Lookups").Activate
If Range("I6") = Yes Then
'Copy and rename sheet
Sheets("Signoff").Copy after:=Sheets("Signoff")
ActiveSheet.Name = Range("AB5")
ActiveSheet.Range("$C$12:$C$43").AutoFilter Field:=1
Rows("1:50").Select
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("C12:C43").Select
Selection.AutoFilter
ActiveSheet.Range("$C$12:$C$43").AutoFilter Field:=1, Criteria1:="<>"
Range("C12").Select
'Move sheet to new workbook
ActiveSheet.Select
ActiveSheet.Copy Before:=Workbooks(Aname).Sheet1
Windows(Aname).Activate
Workbook.Save
Windows("HumanWaveSignOff (Nick).xlsm").Activate
Range("F23").Select
'Delete Non-Formulae sheet
ActiveSheet.Delete
Sheets("Signoff").Select
Else
End If
'Send attached to mail for Manager & HR
Sheets("Lookups").Activate
If Range("I9") = Yes Then
Set Mail_Object = CreateObject("Outlook.Application")
With Mail_Object.CreateItem(o)
'Change Title to suit
.Subject = "Hours Sign Off"
'Update with Manager Name
.To = Range("AB7")
.cc = "someone@here"
'Change as required
.Body = "As attached, please see hours sign off for " & Range("AB4")
'Nominate the file to send
.Attachments.Add "C:\...\pdf\" & Range("AB4") & ".pdf"
.Send
End With
Else
End If
'Send attached to mail for HR
If Range("I10") = Yes Then
Set Mail_Object = CreateObject("Outlook.Application")
With Mail_Object.CreateItem(o)
'Change Title to suit
.Subject = "Hours Sign Off"
'Update with Manager Name
.To = "someone@here"
'Change as required
.Body = "As attached, please see hours sign off for " & Range("AB4")
'Nominate the file to send
.Attachments.Add "C:\...\pdf\" & Range("AB4") & ".pdf"
.Send
End With
End If
End If
'Loop to next name in list
Next x1 <-----------------------------------------------------------------------------------------------------------------------------this is where the compile error happens
Erase arr1
'Clear duplicated names from Tasks tab
Sheets("Tasks").Select
Range("A:A").SpecialCells(xlFormulas).ClearContents
Sheets("Signoff").Select
Range("D4").Select
'Clear Tasks and HWExport Tabs
Sheets("HW Export").Select
Range("C1:AI1000").Select
Selection.ClearContents
Range("C1").Select
Sheets("Tasks").Select
Range("A1:AI1000").Select
Selection.ClearContents
Range("A1").Select
Sheets("Signoff").Select
Range("C1").Select
Next x
Erase arr
GetOut:
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
I've tried to indent the code to show all the If arguments are inside the 2nd For/Next. I expect the problem is having a For/Next inside a For/Next?
Any help would be greatly appreciated.