prevent selection highlighted cells

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,429
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
hi experts

I no know if what I'm asking it , it's possible I would prevent select any cell is highlighted if add message box " you can't select highlighted cells" it will a great

note : if I select the cells are highlighted and locate within them empty cell or not color cells it should prevent after show message should select the cells are filled without contain color
a.xlsx
ABCDEFGHIJKLMN
4
5FFFF
6AABBFF
7AA
8DD
9DDAAAA
10
11DDDD
12CCDD
13
14FFFF
15FFF
16
DD
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Try putting this is n the worksheet code, it moves the selection down a row if the cell has a fill
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Interior.Pattern > 0 Then
 Target.Offset(1, 0).Select
 MsgBox ("you can't select highlighted cells")
End If
End Sub
 
Upvote 0
thanks
but if I specify all the cells whether highlighted or not it doesn't work , can you fix it or it's impossible do that ?
 
Upvote 0
but if I specify all the cells whether highlighted or not it doesn't work , can you fix it or it's impossible do that ?
Do you mean like if you select ALL the cells at once?
Or maybe any other multi-cell range?
 
Upvote 0
@Joe4
Do you mean like if you select ALL the cells at once?
yes
like this
1.PNG
 
Upvote 0
A multi-cell range should not be a problem, we can check each cell in the selection.
But I don't think we want to do that if they select ALL cells, as that would be millions of cells to check and will REALLY slow down your workbook.
I think we may want to add code that does not allow them to select ALL cells. Is that all right with you?

Also, how exactly is this formatting done?
Is it done manually, or is it being done by Conditional Formatting?
 
Upvote 0
if that is the case try this code:
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
tr = Target.Rows.Count
If Target.Count > 1 Then
 For Each cell In Target
   If cell.Interior.Pattern > 0 Then
   MsgBox ("you can't select highlighted cells")
   Target.Offset(tr + 1, 0).Select
   Exit For
   End If
 Next cell
Else
    If Target.Interior.Pattern > 0 Then
     Target.Offset(1, 0).Select
     MsgBox ("you can't select highlighted cells")
    End If
End If
End Sub
 
Upvote 0
@offthelip wow ! brilliant but still there is something after show message it should select cells are not highlighted just the cells are filled values like this
1.PNG
 
Upvote 0

Forum statistics

Threads
1,213,532
Messages
6,114,177
Members
448,554
Latest member
Gleisner2

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