Automatic Conditional Formatting

smitpau

Board Regular
Joined
Apr 2, 2020
Messages
167
Office Version
  1. 365
Platform
  1. Windows
Hi,

I'd appreciate some help please with the below.

The idea is to have only ever one cell selected with "Yes", so that if the cell with "Yes" selected changes the previous cell with "Yes" becomes a "No"

I've attempted something like this below, but am struggling to change the old "Yes" to a "No"


Thanks for reading

PS appreciate the title is slightly misleading but fixing the old "Yes" to turn to "No" will mean the conditional formatting then fully works.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Conditional formatting can only change the appearance (formatting) of the cells, it can not change what is in them.

Most likely, you will need a worksheet change event (vba) however there is insufficient information in your post for me to provide the code that you will need.

Most users of this forum are unable to download attached files due to security restrictions, those that are able to are often unwilling, especially those uploaded by members who are not well known within the community.
 
Upvote 0
That really isn't Conditiona Formatting. Conditional Formatting only changes the format of a cell, not its actual contents.
It sounds like what you need is a Worksheet_Change event procedure, which is code that runs automatically upon some cell being updated.
Please let us know what ranges that this applies to, and we can help you set that up.

EDIT: Looks like Jason and I on thinking on the same wavelength!
 
Upvote 0
Yes thanks both appreciate the title is wrong but was too late to change it.

The code would be that when one cell says "Yes" the other cells say "No".

So for example say range A1:A3 A1 was "Yes" so A2:A3 are "No", if A2 becomes "Yes" then A1 and A3 become "No".

Hope that is clear.

Thanks
 
Upvote 0
Right-click on the sheet tab name at the bottom of the screen, select View Code, and paste this VBA code in the resulting VB Editor window:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim cell As Range
    Dim rng As Range
    
'   Enter range to apply this code to
    Set rng = Range("A1:A3")
    
'   Only run if a single cell has been manually updated
    If Target.CountLarge > 1 Then Exit Sub
    
'   Check to see if update is made in the desired range
    If Intersect(Target, rng) Is Nothing Then Exit Sub
    
'   Check to see if updated cell value is "Yes"
    If Target = "Yes" Then
        Application.EnableEvents = False
'       Loop through range
        For Each cell In rng
            If cell.Address <> Target.Address Then cell = "No"
        Next cell
        Application.EnableEvents = True
    End If
    
End Sub
This should automatically do what you want in the range A1:A3.
 
Upvote 0
Haha thanks does the job perfectly, very cool.

Also appreciate the annotations in the code helps me to follow and learn.
 
Upvote 0
You are welcome.
Let me know if you have any questions about any of the particulars of the code, and I will be happy to answer them for you.
 
Upvote 0

Forum statistics

Threads
1,214,618
Messages
6,120,544
Members
448,970
Latest member
kennimack

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