PDA

View Full Version : Is this possible ?



paleaux
08-09-2011, 12:35 PM
I have a workbook with multiple worksheets, the main one being the
"Timesheet", currently I have some vba that copies and paste a certain criteria from "Gate Log" into the "Timesheet" (Company, Employee, and Total Hours).
I would like to add a Command Button into "AF1" that says "Validate Timesheet"
what would happen is the contractor timekeeper would have to click the
"Validate Timesheet" before she could "Save and Close" If he/she try's to
"Save and Close" with out clicking the "Validate Timesheet" command button it would give them an Error Msg. "Please Validate Timesheet"
When the Timekeeper clicks "Validate Timesheet" command button it
automatically Time Stamp the (Time and Date, as well as the Windows Username) into AF2:AF300

Seperate Issue:
Total Hours is copied from the Gate Log as mentioned above to have the cell change colors when it is altered.
Example:
Total Hours "L2"=10.00, Altered to 10.30= Yellow Cell
Total Hours "L300"= 10.00 Altered to 11.00 = Red Cell

This would help me identify what over rides need to be done in an expeditous manor.

Any help will be very much appreciated. I am just learning vba so my expertise leave alot to be desired but I am trying.

Thanks !

Bob Phillips
08-09-2011, 01:21 PM
In a standard code module



Global ValidateFlag As Boolean

Public Function ValidateTimesheet()
With Worksheets("Timesheet").Range("AF2:AF300")

.Value2 = Environ("Username")
.Offset(0, 1).Value2 = Format(Now, "dd mmm yyy hh:mm:ss")
End With

ValidateFlag = True
End Function


assign the button to this.

In the ThisWorkbook code module



Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Not ValidateFlag Then

MsgBox "Data not validated. Validate and re-try", vbOKOnly + vbCritical, "Validate Timesheet"
Cancel = True
End If
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If Not ValidateFlag Then

MsgBox "Data not validated. Validate and re-try", vbOKOnly + vbCritical, "Validate Timesheet"
Cancel = True
End If
End Sub