ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro Not working in Shared workbook (https://www.excelbanter.com/excel-programming/429835-macro-not-working-shared-workbook.html)

Sunil Pradhan[_2_]

Macro Not working in Shared workbook
 
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



All times are GMT +1. The time now is 09:42 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com