Code removes conditional formatting

gaz1959

New Member
Joined
Jul 19, 2017
Messages
20
Hello,
Most of the codes that I use are either obtained by a combination of internet search, a couple of books, or by using the recorder. Hence I realise they may be very clunky, but eventually they work and do the job.

Anyway when a cell in a range is selected, the cell colour is yellow and the cell value is displayed in cell D3, when another cell in the range is selected the previous cell is no longer yellow but the new cell is now yellow and its value is in D3. This works OK.

The other puts a tick into the cell when double-clicked, and removed when double clicked again. This works OK.

There are 3 problems:
1. I have conditional formatting applied (if a tick - colour cell green) to the named range of cells that the tick is inserted into, but the conditional formatting is removed when ticked
2. The value in cell D3 is removed when a tick is applied, so it no longer displays the value of the yellow cell.
3. To ease navigation I would normally lock cells and protect the sheet without the option for the user to select locked cells. If I do this then the code won’t work, so I have the select locked cells option applied, but then navigation is all over the place. The yellow cells contain formula so must be locked, the tick cells only have a tick or not. Any suggestions, maybe code to only apply select locked cells to the named range?

Thanks in anticipation.


Private Sub Worksheet_BeforeDoubleClick(ByVal target As Range, Cancel As Boolean)
'====DOUBLE CLICK INSERTS A TICK INTO THE CELL, DOUBLE CLICK AGAIN TO CLEAR THE TICK
'these are the tick boxes in the TickBoxes range
'I4:I19,L4:L19,O4:O19,R4:R19,U4:U19,X4:X19,AA4:AA19,
'AD4:AD19,AG4:AG19,AJ4:AJ19,AM4:AM19,AP4:AP19
‘,AS4:AS19,AV4:AV19,AY4:AY19,BB4:BB19

If Not Intersect(target, Range("TickBoxes")) Is Nothing Then
Application.EnableEvents = False
If ActiveCell.Value = ChrW(&H2713) Then
ActiveCell.ClearContents
Else
ActiveCell.Value = ChrW(&H2713) 'character for tick mark
End If
Cancel = True
End If
Application.EnableEvents = True
End Sub

Private Sub Worksheet_SelectionChange(ByVal target As Range)
'==== SELECT A CELL IN THE RANGE, CELL GOES YELLOW TO SHOW IT'S SELECTED, VALUE IS DISPLAYED IN D3 =======
'PROTECTS SHEET AT END WITH SELECT LOCKED CELLS*****
'CELLS IN NAMED RANGE ("J2:J30,M2:M30,P2:P30,S2:S30,V2:V30,Y5:Y22,AB2:AB30,AE2:AE30"))
Sheets("CHIPS").Unprotect 'Password:="123456" '
'PUTS THE SHOP NAME INTO D3

If Application.Intersect(target, Range("Shops")) Is Nothing Then ' the selected cell is not in the named range
Range("D3") = "" 'so don't put the cell value into D3
Else: Range("D3").Value = ActiveCell.Value 'but if in the range put selected shop name into D3
End If
'CHANGES THE SELECTED CELL COLOUR TO YELLOW
If Application.Intersect(target, Range("Shops")) Is Nothing Then
Range("A3") = ""
Else:
With target
.Worksheet.Cells.FormatConditions.Delete
.FormatConditions.Add xlExpression, , "TRUE"
.FormatConditions(1).Interior.Color = vbYellow
End With
End If
Sheets("CHIPS").Protect 'Password:="123456"
End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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