Running Macro on a Protected Sheet (code input)

XL User

New Member
Joined
Apr 11, 2018
Messages
8
Hi all,

I understand there's already been several posts re: this in the past, but could someone give me an example code and where to place it exactly within my existing code? Below is the code I am using. It's basically for a time & motion tracking file

Sub startStopTimer()
If Range("timer.button.label") = "Start" Then
Range("time.stamp.start").Offset(Range("count.of.timestamps") + 1).Value = Now
Range("timer.button.label") = "Stop"
Range("time.stamp.start").Offset(Range("count.of.timestamps"), -2).Value = Range("activity")
Range("time.stamp.start").Offset(Range("count.of.timestamps"), -1).Value = Range("lob")
Range("time.stamp.start").Offset(Range("count.of.timestamps"), -5).Value = Range("employee.id")
Range("time.stamp.start").Offset(Range("count.of.timestamps"), -4).Value = Range("employee.name")
Range("time.stamp.start").Offset(Range("count.of.timestamps"), -3).Value = Range("employee.dept")
Range("time.stamp.start").Offset(Range("count.of.timestamps"), 3).Value = Range("transaction.id")
Else
Range("time.stamp.start").Offset(Range("count.of.timestamps"), 1).Value = Now
Range("time.stamp.start").Offset(Range("count.of.timestamps"), 2).Value = Now - Range("time.stamp.start").Offset(Range("count.of.timestamps"))
Range("timer.button.label") = "Start"
Range("D9").Select
Selection.ClearContents
Range("D9").Select
End If
End Sub

I've already tried several suggestions I found in previous threads... Please advise I'm at my wit's end.


Cheerio
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
This is assuming the sheet is the active sheet since you did not specify a sheet in the code.
Code:
[COLOR=#008000]'this line unprotects the sheet. it needs to be before any lines of code that would need a unprotected sheet[/COLOR]
ActiveSheet.Unprotect "ifyouwantapasworditgoeshere"

[COLOR=#008000]'your code here[/COLOR]

[COLOR=#008000]'this protects the sheet[/COLOR]
ActiveSheet.Protect "ifyouwantapasworditgoeshere"
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top