Macro Not working in Shared workbook

S

Sunil Pradhan

I have following vba code in excelworksheet. but i am getting run time error
1004 - method unprotect of object '_worksheet' failed while using it. Please
advise how i will be able to run these codes in shared workbook.



Private Sub btn_start_click()
mystartrow = 11
Do While Sheet1.Cells(mystartrow, 5).Value <> ""
If mystartrow = 35 Then
Exit Sub
End If

If Sheet1.Cells(mystartrow, 5).Value <> "" Then
mystartrow = mystartrow + 1
End If
Loop
Sheet1.Unprotect "protection"
Sheet1.Cells(mystartrow, 5) = (Now())
btn_start.Enabled = False
btn_end.Enabled = True
Sheet1.Protect "protection"
End Sub
Private Sub btn_end_click()
myendrow = 11
Do While Sheet1.Cells(myendrow, 6).Value <> ""
If myendrow = 35 Then
Exit Sub
End If

If Sheet1.Cells(myendrow, 6).Value <> "" Then
myendrow = myendrow + 1
End If
Loop
Sheet1.Unprotect "protection"
Sheet1.Cells(myendrow, 6) = (Now())
btn_end.Enabled = False
btn_start.Enabled = True
Sheet1.Protect "protection"
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top