A macro to select every sheet on page the is not locked?

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,210
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

I just want to go back and fix all my sheets as the number of rogue unlocked cells is becoming large, (mostly my rushing things over the year with a copy here paste there)
Anyway,
I'd just like a macro that Selects all the unlocked cells on a sheet, so I can save time checking each sheet manually

please help if you can

Thanks

Tony
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Assuming that you have checked the box that allows users to select unlocked cells when you protected the worksheet try...

Code:
Sub selectUnlockedCells()
    Dim UnlockedCells As Range, myCell As Range

    For Each myCell In ActiveSheet.UsedRange
        If Not myCell.Locked Then
            If UnlockedCells Is Nothing Then
                Set UnlockedCells = myCell
            Else
                Set UnlockedCells = Union(UnlockedCells, myCell)
            End If
        End If
    Next myCell

    If UnlockedCells Is Nothing Then
        MsgBox "No unlocked cells were found.", vbExclamation
    Else
        UnlockedCells.Select
    End If

End Sub

By the way you could have easily Googled this question as there are loads of examples online :rolleyes:
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,164
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