VBA Lock and unlock a sheet.

Genetu

New Member
Joined
Apr 20, 2022
Messages
23
Office Version
  1. 2016
Platform
  1. Windows
I have a sheet with a formula and there is a VBA code run on it. The formula should be hidden (protected). When the code is run it can not change the Vloockup value of the cell. The first value is continued till the end. When the formula is unprotected everything is OK. But I need the formula to be hidden. This is the step I trying to fix.

VBA Code:
Sub vlookup_Value()
     'Unprotect the sheet and formula

            'Any code .........

    'Protect sheet and cells with the formula
End sub
 
Sanjeev1976 great job the only thing left is unprotecting other cells except for formulas. Check the code; perfectly run the main code after unprotecting the sheet, through "execute code". But other cells could not accept any data. The dialogue box "The cell you are trying to change is protected...".
 
Upvote 0

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Sanjeev1976 great job the only thing left is unprotecting other cells except for formulas. Check the code; perfectly run the main code after unprotecting the sheet, through "execute code". But other cells could not accept any data. The dialogue box "The cell you are trying to change is protected...".
You need to tell exactly what you want to do with the other cells. This code unprotects the sheet performs what is mentioned in the Execute Code and then protects the sheet again.

Whatever you need to do should be part of the Execute Code or else you can simply unprotect the sheet and continue with what needs to be done.
 
Upvote 0
You need to tell exactly what you want to do with the other cells. This code unprotects the sheet performs what is mentioned in the Execute Code and then protects the sheet again.

Whatever you need to do should be part of the Execute Code or else you can simply unprotect the sheet and continue with what needs to be done.
Ok, Sir. What I need is a sheet that has a formula. The formula must not be edited but hidden (not shown on the formula bar). To do that the sheet must be protected. Other cells, except formula cells, should accept and edit any value. In the execute code, if [A1], [A2], and [A4] values were typed on the cell, you can't after running the code twice. But this is done manually but I need to do this in VBA.
All formulas are hidden and protected, other cells should accept & edit any data even after running the code many times. This is what I want, Sanjeev1976. Thank you in advance.
 
Upvote 0
Select the entire sheet and format all the cells except cells [A1], [A2], and [A4] as unlocked and not hidden and only the cells [A1], [A2], and [A4] as locked and hidden. Then you are good to go with the current VBA code
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,039
Members
449,063
Latest member
ak94

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