VBA Protected sheet, except a Range

Damkilde1986

New Member
Joined
Feb 22, 2019
Messages
9
Good day,

Please bear with me.. I am fairly new with regards to VBA, and therefore need some assitance.
Currently, I am working on a sheet to be used by operators when planning a workweek. Each cell in the Range("B28:EO28") represent a time period. I have created several buttons, which insert a timeblock from selected cell, within the range mentioned.

Here comes my question. I need to lock all other cells, and still be able to insert timeblocks within the range. How can I do this?

I know above info is not alot, but hope some of you might be able to assist, or send me in the right direction.

Thanks in advance!

Best,
Daniel
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
This is similar to question posted here https://www.mrexcel.com/forum/excel-questions/1088464-fixed-operation-range.html
- I have modified the reply from @footoo in answer your question
- user is prevented from selecting any sheets other than those specified

Put this code in the SHEET module
right-click on sheet tab \ View Code \ paste into that window \ {ALT}{F11} to go back to Excel
The first 2 lines must go at the TOP of the module above all procedures

Code:
Option Explicit
Private PrevCell As Range

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   If PrevCell Is Nothing Then Set PrevCell = Range("B28")
   Application.EnableEvents = False
   If Intersect(Target, [B28:EO28]) Is Nothing Then
      PrevCell.Select
   ElseIf Target.Count <> Intersect(Target, [B28:EO28]).Count Then
      PrevCell.Select
   Else
      Set PrevCell = Target
   End If
   Application.EnableEvents = True
End Sub



'B28:EO28"
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,801
Messages
6,121,644
Members
449,045
Latest member
Marcus05

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