I am sticking my nose into VBA for Excel for the first time and I need some help. I recorded macros and then put them into VBA. I will show you my code then the questions below. The task at hand is to help managers figure time cards, we are still in the 19th century. I used an example off of the internet to set up the basics that works correctly. Now I want to be able to have several buttons that allows the manager to clear the information just finished, reset the lunch time, and repopulated the basic shift times. That way they only have to change the ending time in most cases.
Private Sub cmdResetTime_Click()
‘ ResetLunchTime Macro
‘ Macro recorded 12/29/2005 by Fay Yocum
‘ Keyboard Shortcut: Ctrl+Shift+T
‘ Resets the lunch time break to 30 minutes
Range(“B4:B17”).Select
ActiveCell.FormulaR1C1 = “12:30:00 AM”
Range(“B5”).Select
ActiveCell.FormulaR1C1 = “12:30:00 AM”
Range(“B6”).Select
ActiveCell.FormulaR1C1 = “12:30:00 AM”
Range(“B7”).Select
ActiveCell.FormulaR1C1 = “12:30:00 AM”
Range(“B8”).Select
ActiveCell.FormulaR1C1 = “12:30:00 AM”
Range(“B9”).Select
ActiveCell.FormulaR1C1 = “12:30:00 AM”
Range(“B10”).Select
ActiveCell.FormulaR1C1 = “12:30:00 AM”
Range(“B11”).Select
ActiveCell.FormulaR1C1 = “12:30:00 AM”
Range(“B12”).Select
ActiveCell.FormulaR1C1 = “12:30:00 AM”
Range(“B13”).Select
ActiveCell.FormulaR1C1 = “12:30:00 AM”
Range(“B14”).Select
ActiveCell.FormulaR1C1 = “12:30:00 AM”
Range(“B15”).Select
ActiveCell.FormulaR1C1 = “12:30:00 AM”
Range(“B16”).Select
ActiveCell.FormulaR1C1 = “12:30:00 AM”
Range(“B17”).Select
ActiveCell.FormulaR1C1 = “12:30:00 AM”
‘ ClearFields Macro
‘ Macro recorded 12/29/2005 by Fay Yocum
‘
‘ Keyboard Shortcut: Ctrl+Shift+C
‘
Range(“C4:D17”).Select
Selection.ClearContents
Range(“I4:J17”).Select
Selection.ClearContents
Sheets(“Sheet2”).Select
Range(“A2:B15”).Select
Selection.Copy
Sheets(“Sheet1”).Select
Range(“C4”).Select
ActiveSheet.Paste
Range(“C4”).Select
End Sub
Question 1: There has to be a shorter way to reset the lunch time at the top?
Question 2: I have the lunch column format set as time. If a person only takes a 10 minute lunch break the total work time figures correctly at 8.50. The regular hours works out as 8 and the overtime comes in at 0.33. I tried changing the format of the lunch column to general and that didn’t work. Staff does not clock in or out for lunch. Essentially when the managers figure the time card they just delete the first 30 minutes. I am thinking I am just better off telling them to enter the start of the shift 30 minutes later. What do you think?
Question 3: When i run the ClearFields Macro section as a Macro it works like I want it to work. But with the code attached to a command button it hangs on the Range(“A2:B15”).Select line and the error message is Select method of Range class failed. Why?
I have attached the file. Any and all help and instruction would be appreciated.
Thank you. Fay