Lock Cells

jordanstuart

New Member
Joined
Jul 27, 2017
Messages
3
I'm trying to sort data in a range of data, but i'm need to lock some of the cells within to ensure that the formulas in the cells aren't changed. Here is an example of the data that I need to sort. Is there a formula or VBA code to lock these cells, but still allow them to be sorted based on their score?

[TABLE="width: 1031"]
<colgroup><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col></colgroup><tbody>[TR]
[TD]Person[/TD]
[TD]Region[/TD]
[TD]HC[/TD]
[TD]OOO[/TD]
[TD]UP OOO[/TD]
[TD]SS[/TD]
[TD]AHC[/TD]
[TD]DPH[/TD]
[TD]ISMs[/TD]
[TD]%[/TD]
[TD]PPD[/TD]
[TD]Sub[/TD]
[TD]DPH[/TD]
[TD]ISM[/TD]
[TD]Goals[/TD]
[TD]SCORE[/TD]
[/TR]
[TR]
[TD]Ashley[/TD]
[TD]Florida[/TD]
[TD]22[/TD]
[TD]15[/TD]
[TD]47.25[/TD]
[TD]3[/TD]
[TD]18.28[/TD]
[TD]60.47[/TD]
[TD]93.21%[/TD]
[TD]4.90%[/TD]
[TD]24.64[/TD]
[TD]27.40[/TD]
[TD]2[/TD]
[TD]0[/TD]
[TD]0.00[/TD]
[TD]29.40[/TD]
[/TR]
[TR]
[TD]Alex[/TD]
[TD]Colorado[/TD]
[TD]25[/TD]
[TD]19[/TD]
[TD]63.8[/TD]
[TD]18[/TD]
[TD]21.19[/TD]
[TD]69.22[/TD]
[TD]92.96%[/TD]
[TD]3.82%[/TD]
[TD]22.42[/TD]
[TD]24.88[/TD]
[TD]2[/TD]
[TD]0[/TD]
[TD]0.50[/TD]
[TD]27.38[/TD]
[/TR]
[TR]
[TD]Mike[/TD]
[TD]Texas[/TD]
[TD]23[/TD]
[TD]21[/TD]
[TD]47.25[/TD]
[TD]21[/TD]
[TD]20.16[/TD]
[TD]70.92[/TD]
[TD]93.92%[/TD]
[TD]3.62%[/TD]
[TD]21.91[/TD]
[TD]24.32[/TD]
[TD]2[/TD]
[TD]0[/TD]
[TD]0.50[/TD]
[TD]26.82[/TD]
[/TR]
[TR]
[TD]Dan[/TD]
[TD]Texas[/TD]
[TD]21[/TD]
[TD]19[/TD]
[TD]62.75[/TD]
[TD]15[/TD]
[TD]16.84[/TD]
[TD]69.52[/TD]
[TD]96.78%[/TD]
[TD]3.38%[/TD]
[TD]20.11[/TD]
[TD]22.38[/TD]
[TD]2[/TD]
[TD]1[/TD]
[TD]0.75[/TD]
[TD]26.13[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
simple version of it. I am sure someone could put together a more elaborate version.

highlight your selected area and then run -

Code:
Sub ProtectCells()
    Dim c As Range
    
        For Each c In Selection
            Selection.Locked = True
            Selection.FormulaHidden = True
        Next c
            With ActiveSheet
                .Protect Password:="YourPassword", AllowFiltering:=True
                .EnableSelection = xlUnlockedCells
            End With
End Sub
 
Last edited:
Upvote 0
We are trying to use this, but it is locking everything so we are unable to sort this. Are there any other suggestions you have for fixing this?
 
Upvote 0
Try adding this
Code:
    Cells.Locked = False
before the For Each
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,191
Members
453,021
Latest member
pingpong7117

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