VBA luddite

Marvyn

New Member
Joined
Jun 23, 2022
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi.

Apologies for my lack of understanding of VBA (and any forum rules inadvertently broken here) but I'm looking for help.

I have created a workbook with multiple sheets which various employees can input on. There is a Summary sheet at the front which changes when someone inputs on the other sheets.

I have managed to work out the code for this but need to protect the Summary sheet from being altered by users.

I've found various suggestions around the UserInterfaceOnly function but everything I try stops the code working from the other sheets (ie. the Summary sheet no longer updates when something is input on another sheet).

Ideally, I'd like the Summary sheet to be 'read only' but still allow macros from other sheets to alter it and for this to remain the case even if the workbook is opened/ closed.

Many thanks in advance for any help.

Should have said - if you are able to be quite specific with any suggestions I'd be really grateful; my knowledge of VBA is non-existent!
 
Last edited by a moderator:

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Welcome to the Board!

You will want to lock/protect all the cells on your Summary page so that they cannot be altered.
See here for how to do that: Lock cells to protect them

How exactly is your "Summary" sheet being updated?
If by formulas, then you shouldn't need to do anything at all. Protecting the sheet will not prevent the formulas from recalculating.

If the Summary sheet is being updated by VBA code, then you will want to update that VBA code to temporarily unprotect the Summary sheet before making changes to it (and then have VBA re-protect it after making the updates).
This link shows you how to protect/unprotect sheets in your VBA code: VBA Protect / Unprotect Worksheets - Automate Excel
 
Upvote 0
Hi Joe.

Thanks for the reply.

The Summary sheet is being updated by VBA code.

Where would I include the
VBA Code:
Worksheets("Sheet1").Unprotect "Password"
?

Would it come before my Sub routine or should it be contained within it? (Again, apologies for my ignorance...)
 
Upvote 0
You want to put it right in the procedure, i.e. structured something like this:
VBA Code:
Sub MyProcedure()

    Worksheets("Sheet1").Unprotect "Password"

'   Your code to make changes to Sheet1

    Worksheets("Sheet1").Protect "Password"

End Sub

The flow is quite logical:
- First, unprotect the sheet
- Second, make the desired changes to the sheet
- Third, re-protect the sheet

And you will want that in any procedure that is supposed to make changes to the sheet.

One thing to note/watch for is if you have any "Exit Sub" statements in your code (or anything else that might kick you out of the code before hitting the end).
Because that could unlock the Sheet and not re-protect it. You want to make sure that all exits re-protect the sheet.
 
Upvote 0
Solution
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,214,991
Messages
6,122,628
Members
449,095
Latest member
bsb1122

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