Password Protection for a MACRO

Northern NY Design

New Member
Joined
Sep 24, 2024
Messages
25
Office Version
  1. 365
Platform
  1. Windows
I am trying to make my MACRO (s) so that when someone clicks it they are prompted to enter "YES". I have read numerous threads on this but I cannot seem to make it work.

Below is the code for my MACRO, please show me where, and what to enter. Thank you in advance.

Sub CLEARROW18()
'
' CLEARROW18 Macro
' Use this MACRO to remove a driver from ROW 18 of the CURRENT DRIVER DATA without removing formulas or harming this spreadsheet set.
'
Sheets("CURRENT DRIVER DATA").Select
ActiveSheet.Unprotect
Range("A20:C20").Select
Selection.ClearContents
Range("E20").Select
Selection.ClearContents
Range("G20:AC20").Select
Selection.ClearContents
Range("AE20:AF20").Select
Selection.ClearContents
Range("AG20:AN20").Select
Selection.ClearContents
Range("AS20:AZ20").Select
Selection.ClearContents
Range("BE20:BL20").Select
Selection.ClearContents
Range("BQ20:BX20").Select
Selection.ClearContents
Range("CC20:CJ20").Select
Selection.ClearContents
Range("CO20:CV20").Select
Selection.ClearContents
Range("DA20:DH20").Select
Selection.ClearContents
Range("DM20:DT20").Select
Selection.ClearContents
Range("DY20:EF20").Select
Selection.ClearContents
Range("EK20:ER20").Select
Selection.ClearContents
Range("EW20:FD20").Select
Selection.ClearContents
Range("FI20:FP20").Select
Selection.ClearContents
Range("C20").Select
Sheets("CURRENT DRIVER DATA").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True

End Sub
 
Not quite. Replace the red line with your entire code which is between "Sub" and "End Sub".
Rich (BB code):
Sub RESETTRACKER()
    If MsgBox("Do you want to proceed?", vbYesNo) = vbYes Then
        'your code here
    End If
End Sub
Your code has an extremely large number of unnecessary lines and "Select" statements which makes it very time consuming to debug. It would be easier to help if you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
 
Upvote 0

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Not quite. Replace the red line with your entire code which is between "Sub" and "End Sub".
Rich (BB code):
Sub RESETTRACKER()
    If MsgBox("Do you want to proceed?", vbYesNo) = vbYes Then
        'your code here
    End If
End Sub
Your code has an extremely large number of unnecessary lines and "Select" statements which makes it very time consuming to debug. It would be easier to help if you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
I understand that it would be easier that way but some of the linked tabs have a lot of personal information on my drivers so I cannot share it.
 
Upvote 0
Can you replace the personal information with dummy data? I wouldn't need all your data in each sheet. A dozen rows or so of data should be enough.
 
Upvote 0
Yes, I did that. I saved the file to BOX.com. I am working on the macros in the CURRENT DRIVER DATA tab and the CURRENT WEEK TAB. I need the CURRENT DRIVER DATA tab macro to sort the entire range by the drivers' names (column B) but I need it to ask something to the effect of "ARE YOU SURE YOU WANT TO PERFORM THIS ACTION" and all the user has to do is type "YES". Similarly in the CURRENT WEEK tab, I need the RESET macro to ask the same question before running. The macros are saved as:

SORTCURRENTDRIVERDATA

and

RESETTRACKER

 
Upvote 0
If your current code is working, then copy/paste all the code between the two red lines of code and run the macro.
Rich (BB code):
Sub RESETTRACKER()
    If MsgBox("Do you want to proceed?", vbYesNo) = vbYes Then
        'your code here
    End If
End Sub
 
Upvote 0
Ok, that worked PERFECTLY, except now it creates a new button over the top of the RESET button every time I run the macro? Any suggestions?
 
Upvote 0
I believe your code includes a line that creates the button. Try deleting that line of code.
 
Upvote 0
If your current code is working, then copy/paste all the code between the two red lines of code and run the macro.
Rich (BB code):
Sub RESETTRACKER()
    If MsgBox("Do you want to proceed?", vbYesNo) = vbYes Then
        'your code here
    End If
End Sub
I hit NO and it still ran the macro.
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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