Cell color as the cursor moves (in a protected sheet)

feni1388

Board Regular
Joined
Feb 19, 2018
Messages
141
Office Version
  1. 2021
Platform
  1. Windows
Hello everyone...

I found VBA code to color the active cell and it worked in an unprotected sheet.
I want to use it in a protected sheet where I can input only on several cells and in this sheet I also have another VBA code.
When I put this code, it didn't work but I don't know where the problem is. It always stop at this part -> Cells.Interior.ColorIndex = 0
Can someone point me where the problem is?

Thanks in advance.

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  Dim rFound As Range
 If Not Intersect(Target, Range("I4:I29")) Is Nothing Then
    If Len(Target.Value) > 0 Then
      Cancel = True
      Set rFound = Sheets("Item list").Columns("W").Find(What:=Target.Value, LookAt:=xlPart)
      If rFound Is Nothing Then
        MsgBox Target.Value & "Not found"
      Else
        Application.Goto Reference:=rFound, Scroll:=True
        rFound.EntireRow.Select
      End If
    End If
  End If
  If Not Intersect(Target, Range("K4:K29")) Is Nothing Then
    If Len(Target.Value) > 0 Then
      Cancel = True
      Set rFound = Sheets("Item list").Columns("A").Find(What:=Target.Value, LookAt:=xlWhole)
      If rFound Is Nothing Then
        MsgBox Target.Value & "Not found"
      Else
        Application.Goto Reference:=rFound, Scroll:=True
        rFound.EntireRow.Select
      End If
    End If
  End If
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.ScreenUpdating = False
Cells.Interior.ColorIndex = 0
Target.Interior.Color = vbCyan
Application.ScreenUpdating = True
End Sub
 
You'll have to either unprotect the sheet before changing the colorindex, or -when settings protection- set it to allow formatting cells.
 
Upvote 0
Solution

Forum statistics

Threads
1,226,797
Messages
6,193,051
Members
453,772
Latest member
aastupin

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