PDA

View Full Version : Mismatch error



junior6202
03-30-2015, 10:17 PM
I created a form to populate a worksheet. The code works perfectly if a record already exist, I manually entered ID row 1 and after running the Sub ID 2 populated just fine and so on...

ID
Employee
Task
Hour Started
Hour Ended


1
tom
break
10:20 am



2
jack
cleaning
10:25 am











but fails if there is no record with an ID of 1. Run time error '13' Type Mismatch




ID
Employee
Task
Hour Started
Hour Ended


























Private Sub cmdStart_Click()
Sheet1.Activate

Range("A1").End(xlDown).Offset(1, 0).Select
ActiveCell.Value = ActiveCell.Offset(-1, 0).Value + 1 ' increment by one
ActiveCell.Font.Italic = True

ActiveCell.Offset(0, 1).Value = cboEmployee.Value
ActiveCell.Offset(0, 2).Value = cboTask.Value
ActiveCell.Offset(0, 3).Value = Format(Now(), "hh:mm AM/PM")


End Sub



When I run my code I get a Type mismatch error. Which I understand because the code is trying to add + 1 to ID, my question is how would I get my code to write the first line and then from there on use the increment by one "ActiveCell.Value = ActiveCell.Offset(-1, 0).Value + 1" any advice will be appreciated.

Thanks in advance