OK so I have figured out how to do it. Below are the 3 codes I am using. If I run them one at a time they work perfectly however when I try to run them together by either combining them or calling them the part that sends the emails does not work. The code is very sloppy since I had to learn how to do each step, but hopefully you will be able to read it. If someone could advise what could be causing the email part not to work when they are combined it would be greatly appreciated. I do not receive any error messages.
Sub Main()
Application.ScreenUpdating = False
Dim MyCell As Range, MyRange As Range
Set MyRange = Sheets("Data").Range("AA2")
Set MyRange = Range(MyRange, MyRange.End(xlDown))
For Each MyCell In MyRange
Sheets.Add After:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = MyCell.Value
Next MyCell
Sheets("Data").Select
Dim LR As Long, i As Long
With ActiveSheet
LR = .Range("F" & Rows.Count).End(xlUp).Row
For i = 1 To LR
If .Range("F" & i).Value = "1" Then
.Range("A" & i).Copy
Sheets("Div. 1").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
.Range("B" & i).Copy
Sheets("Div. 1").Range("B" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
.Range("E" & i).Copy
Sheets("Div. 1").Range("C" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
.Range("O" & i).Copy
Sheets("Div. 1").Range("D" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
.Range("X" & i).Copy
Sheets("Div. 1").Range("E" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
End If
Next i
LR = .Range("F" & Rows.Count).End(xlUp).Row
For i = 1 To LR
If .Range("F" & i).Value = "6" Then
.Range("A" & i).Copy
Sheets("Div. 6").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
.Range("B" & i).Copy
Sheets("Div. 6").Range("B" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
.Range("E" & i).Copy
Sheets("Div. 6").Range("C" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
.Range("O" & i).Copy
Sheets("Div. 6").Range("D" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
.Range("X" & i).Copy
Sheets("Div. 6").Range("E" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
End If
Next i
LR = .Range("F" & Rows.Count).End(xlUp).Row
For i = 1 To LR
If .Range("F" & i).Value = "9" Then
.Range("A" & i).Copy
Sheets("Div. 9").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
.Range("B" & i).Copy
Sheets("Div. 9").Range("B" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
.Range("E" & i).Copy
Sheets("Div. 9").Range("C" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
.Range("O" & i).Copy
Sheets("Div. 9").Range("D" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
.Range("X" & i).Copy
Sheets("Div. 9").Range("E" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
End If
Next i
LR = .Range("F" & Rows.Count).End(xlUp).Row
For i = 1 To LR
If .Range("F" & i).Value = "11" Then
.Range("A" & i).Copy
Sheets("Div. 11").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
.Range("B" & i).Copy
Sheets("Div. 11").Range("B" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
.Range("E" & i).Copy
Sheets("Div. 11").Range("C" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
.Range("O" & i).Copy
Sheets("Div. 11").Range("D" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
.Range("X" & i).Copy
Sheets("Div. 11").Range("E" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
End If
Next i
LR = .Range("F" & Rows.Count).End(xlUp).Row
For i = 1 To LR
If .Range("F" & i).Value = "12" Then
.Range("A" & i).Copy
Sheets("Div. 12").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
.Range("B" & i).Copy
Sheets("Div. 12").Range("B" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
.Range("E" & i).Copy
Sheets("Div. 12").Range("C" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
.Range("O" & i).Copy
Sheets("Div. 12").Range("D" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
.Range("X" & i).Copy
Sheets("Div. 12").Range("E" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
End If
Next i
LR = .Range("F" & Rows.Count).End(xlUp).Row
For i = 1 To LR
If .Range("F" & i).Value = "13" Then
.Range("A" & i).Copy
Sheets("Div. 13").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
.Range("B" & i).Copy
Sheets("Div. 13").Range("B" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
.Range("E" & i).Copy
Sheets("Div. 13").Range("C" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
.Range("O" & i).Copy
Sheets("Div. 13").Range("D" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
.Range("X" & i).Copy
Sheets("Div. 13").Range("E" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
End If
Next i
End With
With Sheets("Div. 1")
.Columns("A:E").HorizontalAlignment = xlCenter
.Columns("A:E").EntireColumn.AutoFit
End With
With Sheets("Div. 6")
.Columns("A:E").HorizontalAlignment = xlCenter
.Columns("A:E").EntireColumn.AutoFit
End With
With Sheets("Div. 9")
.Columns("A:E").HorizontalAlignment = xlCenter
.Columns("A:E").EntireColumn.AutoFit
End With
With Sheets("Div. 11")
.Columns("A:E").HorizontalAlignment = xlCenter
.Columns("A:E").EntireColumn.AutoFit
End With
With Sheets("Div. 12")
.Columns("A:E").HorizontalAlignment = xlCenter
.Columns("A:E").EntireColumn.AutoFit
End With
With Sheets("Div. 13")
.Columns("A:E").HorizontalAlignment = xlCenter
.Columns("A:E").EntireColumn.AutoFit
End With
End Sub
Sub Send_Email()
'Working in Excel 2002-2016
Dim Sendrng As Range
On Error GoTo StopMacro
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Sheets("Div. 1").Select
Range(Range("A1:E1"), Range("A1:E1").End(xlDown)).Select
'Note: if the selection is one cell it will send the whole worksheet
Set Sendrng = Selection
'Create the mail and send it
With Sendrng
ActiveWorkbook.EnvelopeVisible = True
With .Parent.MailEnvelope
' Set the optional introduction field thats adds
' some header text to the email body.
.Introduction = "Please advise if I may make the below moves/allocations."
With .Item
.To = ("I removed my email address")
.CC = ""
.BCC = ""
.Subject = ("Division 1 Allocation Requests")
.Send
End With
End With
End With
Sheets("Div. 6").Select
Range(Range("A1:E1"), Range("A1:E1").End(xlDown)).Select
'Note: if the selection is one cell it will send the whole worksheet
Set Sendrng = Selection
'Create the mail and send it
With Sendrng
ActiveWorkbook.EnvelopeVisible = True
With .Parent.MailEnvelope
' Set the optional introduction field thats adds
' some header text to the email body.
.Introduction = "Please advise if I may make the below moves/allocations."
With .Item
.To = ("I removed my email address")
.CC = ""
.BCC = ""
.Subject = ("Division 6 Allocation Requests")
.Send
End With
End With
End With
Sheets("Div. 9").Select
Range(Range("A1:E1"), Range("A1:E1").End(xlDown)).Select
'Note: if the selection is one cell it will send the whole worksheet
Set Sendrng = Selection
'Create the mail and send it
With Sendrng
ActiveWorkbook.EnvelopeVisible = True
With .Parent.MailEnvelope
' Set the optional introduction field thats adds
' some header text to the email body.
.Introduction = "Please advise if I may make the below moves/allocations."
With .Item
.To = ("I removed my email address")
.CC = ""
.BCC = ""
.Subject = ("Division 9 Allocation Requests")
.Send
End With
End With
End With
Sheets("Div. 11").Select
Range(Range("A1:E1"), Range("A1:E1").End(xlDown)).Select
'Note: if the selection is one cell it will send the whole worksheet
Set Sendrng = Selection
'Create the mail and send it
With Sendrng
ActiveWorkbook.EnvelopeVisible = True
With .Parent.MailEnvelope
' Set the optional introduction field thats adds
' some header text to the email body.
.Introduction = "Please advise if I may make the below moves/allocations."
With .Item
.To = ("[email protected]")
.CC = ""
.BCC = ""
.Subject = ("I removed my email address")
.Send
End With
End With
End With
Sheets("Div. 12").Select
Range(Range("A1:E1"), Range("A1:E1").End(xlDown)).Select
'Note: if the selection is one cell it will send the whole worksheet
Set Sendrng = Selection
'Create the mail and send it
With Sendrng
ActiveWorkbook.EnvelopeVisible = True
With .Parent.MailEnvelope
' Set the optional introduction field thats adds
' some header text to the email body.
.Introduction = "Please advise if I may make the below moves/allocations."
With .Item
.To = ("I removed my email address")
.CC = ""
.BCC = ""
.Subject = ("Division 12 Allocation Requests")
.Send
End With
End With
End With
Sheets("Div. 13").Select
Range(Range("A1:E1"), Range("A1:E1").End(xlDown)).Select
'Note: if the selection is one cell it will send the whole worksheet
Set Sendrng = Selection
'Create the mail and send it
With Sendrng
ActiveWorkbook.EnvelopeVisible = True
With .Parent.MailEnvelope
' Set the optional introduction field thats adds
' some header text to the email body.
.Introduction = "Please advise if I may make the below moves/allocations."
With .Item
.To = ("I removed my email address")
.CC = ""
.BCC = ""
.Subject = ("Division 13 Allocation Requests")
.Send
End With
End With
End With
StopMacro:
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
ActiveWorkbook.EnvelopeVisible = False
End Sub
Sub Delete_Sheets()
Application.DisplayAlerts = False
Sheets("Div. 1").Delete
Sheets("Div. 6").Delete
Sheets("Div. 9").Delete
Sheets("Div. 11").Delete
Sheets("Div. 12").Delete
Sheets("Div. 13").Delete
End Sub
Bookmarks