Sub Submit()
'
' Submit Macro
' Copies Time Sheet data to the Submissions tab, clears data that has successfully copied.
'
Application.ScreenUpdating = False
Range("TotalHrs").Select
'***********BEFORE ALLOWING THE USER TO SUBMIT************************************************
'Check to make sure the Priority column has been populated for all entries
Dim c As Range
Dim d As Range
Dim e As Range
Dim f As Range
Dim DataRange As Range
For Each c In Range("Priority")
Set DataRange = Range(Cells(c.Row, 4), Cells(c.Row, 8))
If Application.WorksheetFunction.CountBlank(DataRange) = 1 _
And IsEmpty(Cells(c.Row, 11)) Then
MsgBox "Missing Priority on line " & c.Row - 9, , "Missing Data"
Exit Sub
End If
'Check to make sure if Priority has been filled out that there is a Project/Phase or Task
Set DataRange = Range(Cells(c.Row, 4), Cells(c.Row, 8))
If Application.WorksheetFunction.CountA(DataRange) = 0 _
And Len(Cells(c.Row, 11)) > 0 Then
MsgBox "Missing Project, Phase or Task on line " & c.Row - 9, , "Missing Data"
Exit Sub
End If
Next c
'check to make sure there is only one Project or Task chosen on each line
For Each c In Range("Task")
Set DataRange = Range(Cells(c.Row, 8), Cells(c.Row, 8))
If Application.WorksheetFunction.CountBlank(DataRange) = 0 _
And (Cells(c.Row, 4)) > 0 Then
MsgBox "Only one Project/Phase or Task can be chosen per line. See entry #" & c.Row - 9, vbExclamation, "Oops!"
Exit Sub
End If
Next c
For Each d In Range("Project")
Set DataRange = Range(Cells(d.Row, 4), Cells(d.Row, 4))
If Application.WorksheetFunction.CountBlank(DataRange) = 0 _
And (Cells(d.Row, 8)) <> "" Then
MsgBox "Only one Project/Phase or Task can be chosen per line. Check row #" & d.Row, vbExclamation, "Oops!"
Exit Sub
End If
Next d
'check that there are hours entered for each line using priority column as reference
For Each e In Range("Hrs")
Set DataRange = Range(Cells(e.Row, 20), Cells(e.Row, 20))
If DataRange.Value = "" _
And (Cells(e.Row, 11)) <> "" Then
MsgBox "Missing Hours on line " & e.Row - 9, , "Missing Data"
Exit Sub
End If
Next e
'check that there is either a project or a task entered for each line using priority column as reference
For Each f In Range("Task")
Set DataRange = Range(Cells(f.Row, 8), Cells(f.Row, 8))
If Application.WorksheetFunction.CountBlank(DataRange) > 0 _
And (Cells(f.Row, 4)) = "" _
And (Cells(f.Row, 11)) <> "" _
Then
MsgBox "Missing Project/Phase or Task on line " & f.Row - 9, , "Missing Data"
Exit Sub
End If
Next f
'*****************ONCE THE DATA IS VALID, THE USER IS ALLOWED TO SUBMIT***********************************************
'Copy the Employee Name
Range("EEName").Select
Selection.Copy
Sheets("Submissions").Select
'find the number of entries and set value as number of times to paste the employee name
Range("K10").Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, -5).Select
'how do i set the number in this cell as the number of times to paste the value?
'Find the first blank cell in column A
Set FirstBlankCell = Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
FirstBlankCell.Activate
'Paste the data in as many times as there are entries
With Range(FirstBlankCell, "A" & lastrow&).Select
Selection.PasteSpecial xlValues '***as many times as found in ActiveCell.Offset(0,-5).Select above
End With
'Copy the Project name from the Time Sheet tab
Sheets("Time Sheet").Select
Range("Project").Select
For Each cell In Range("Project")
Sheets("Time Sheet").Select
If Cells(d.Row, 4).Value <> "" Then
cell.Copy
Sheets("Submissions").Select
'On the Submissions tab: find the first blank cell in column B
'Dim FirstBlankCell As Range
Set FirstBlankCell = Range("A" & Rows.Count).End(xlUp).Offset(1, 1)
FirstBlankCell.Activate
'Paste in the copied data
ActiveCell.PasteSpecial xlValues
End If
Next
'Copy the Phase name from the Time Sheet tab
Sheets("Time Sheet").Select
Range("Phase").Select
For Each cell In Range("Phase")
If Cells(1, 3).Value <> "" Then
cell.Copy
Sheets("Submissions").Select
'On the Submissions tab: go to the first cell in the next available line for column C
'Dim FirstBlankCell As Range
Set FirstBlankCell = Range("A" & Rows.Count).End(xlUp).Offset(1, 2)
FirstBlankCell.Activate
'Paste in the copied data
ActiveCell.PasteSpecial xlValues
End If
Next
'Copy the Task name from the Time Sheet tab
Sheets("Time Sheet").Select
Range("Task").Select
For Each cell In Range("Task")
If Cells(0, 1).Value <> "" Then
cell.Copy
Sheets("Submissions").Select
'On the Submissions tab: find the first blank cell in column A
'Dim FirstBlankCell As Range
Set FirstBlankCell = Range("A" & Rows.Count).End(xlUp).Offset(1, 3)
FirstBlankCell.Activate
'Paste in the copied data
ActiveCell.PasteSpecial xlValues
End If
Next
'Copy the Priority
Sheets("Time Sheet").Select
Range("Priority").Select
For Each cell In Range("Priority")
If cell.Value <> "" Then
cell.Copy
Sheets("Submissions").Select
'Find the first blank cell in column C
Set FirstBlankCell = Range("A" & Rows.Count).End(xlUp).Offset(1, 4)
FirstBlankCell.Activate
ActiveCell.PasteSpecial xlValues
Sheets("Time Sheet").Select
End If
Next
'Copy the Short description
Sheets("Time Sheet").Select
Range("ShortDesc").Select
For Each cell In Range("ShortDesc")
If Cells.Offset(0, 1).Value <> "" Then
cell.Copy
Sheets("Submissions").Select
'Find the first blank cell in column F
Set FirstBlankCell = Range("A" & Rows.Count).End(xlUp).Offset(1, 5)
FirstBlankCell.Activate
ActiveCell.PasteSpecial xlValues
Sheets("Time Sheet").Select
End If
Next
'Copy the Week Ending date
Range("To").Select
Selection.Copy
Sheets("Submissions").Select
'Find the FIRST blank cell in column G
Set FirstBlankCell = Range("A" & Rows.Count).End(xlUp).Offset(1, 6)
FirstBlankCell.Activate
'Find the LAST blank cell in column G, if there is data in column E for that row
'Dim lastrow As Long
lastrow = Worksheets("Submissions").Range("E2").End(xlDown).Row
'Paste the data into the range between first and last empty cells related to column E
With Range(FirstBlankCell, "G" & lastrow&).Select
Selection.PasteSpecial xlValues
End With
'Copy the total hours per line
Sheets("Time Sheet").Select
Range("Hrs").Select
For Each cell In Range("Hrs")
If cell.Value <> "" Then
cell.Copy
Sheets("Submissions").Select
'Find the first blank cell in column H
Set FirstBlankCell = Range("A" & Rows.Count).End(xlUp).Offset(1, 7)
FirstBlankCell.Activate
ActiveCell.PasteSpecial xlValues
Sheets("Time Sheet").Select
End If
Next
'Copy formatting to new rows
Selection.Offset(-13, 0).EntireRow.Copy
Selection.EntireRow.PasteSpecial (xlFormats)
Application.CutCopyMode = False
'delete all the data on the timesheet so new info can be entered
Sheets("Time Sheet").Select
Range("D10:G21, I10:S21").Select
Application.CutCopyMode = False
Selection.ClearContents
Range("E4").Select
'ElseIf MsgResult = vbNo Then
'Exit Sub
'End If
Application.ScreenUpdating = True
End Sub
Bookmarks