Corrections to VBA code samples in Texts
1. Problem : Using the IT Essentials text I have worked thru the Chapter on Excel and got through it easy. Came to a stumble when I got to the end of the Macros and Editing in Visual Basic. Bill's Payroll works fine in every way except that when I use the Form to enter thenormal hours and overtime hours the sum function for each total of hours does not work. If I enter the numbers without using the form it works fine. I have tried protecting and unprotecting, locking and unlocking the sheet but to no avail.
Answer1 : There's a small error in the macro code, Helen. If you have a look at the code, the line that refers to the Net Pay refers to it as lblNetPay:
lblNetPay = Format(Cells(rownumber, 8).Value, "Currency")
whereas in fact the cell is a text box, so all you have to do is alter the lbl to a txt and it works beautifully:
txtNetPay = Format(Cells(rownumber, 8).Value, "Currency")
Answer2 : If you force a formatting of the txtNormalHours and txtOver Hours textboxes to a number it is working on your sample file you have sent me.
rownumber = cboNames.ListIndex + 8
If rownumber >= 8 Then
Cells(rownumber, 2).Value = Format(txtNormalHours.Value, Number)
Cells(rownumber, 3).Value = Format(txtOverHours.Value, Number)
lblNetPay = Format(Cells(rownumber, 8).Value, "$#,##0.00")
End If
In the absence of this , the figures put into the spreadsheet are appearing as just a single number and no decimal component suggesting a different format.