Click to add, Click to remove

christianbiker

Active Member
Joined
Feb 3, 2006
Messages
379
Greetings all,

I am wondering if there is a way to specify that when any empty cell in a specific range is clicked on that an "x" populate that cell, and the same thing in reverse...if a cell in the same range is clicked that has an "x" that the "x" be removed and the cell is now blank again?

Any help would be appreciated.

Thanks,
Chad
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Try this: right click the sheet tab, select View code and paste in

Rich (BB code):
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Intersect(Target, Range("A3:F5")) Is Nothing Then Exit Sub
Select Case Target.Value
    Case "x": Target.ClearContents
    Case "": Target.Value = "x"
End Select
End Sub

Change the range to suit.
 
Upvote 0
Not tested sufficiently:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim r As Range
Set r = Range("A1:A10")
Set rsect = Application.Intersect(r, Target)
If Not rsect Is Nothing Then
    Select Case Target.Value2
    Case ""
    Target.Value2 = "X"
    Case "X"
    Target.Value2 = ""
    End Select
End If
End Sub
 
Upvote 0
I used VoG's code below and it works great, however I have noticed that I cannot clear the entire range that this code is used for by selecting all cells and clearing. This is part of a form that other people will be completing and I need to have a reset function built in for them as a macro if they want to clear it.

How can I get around that issue?

Thanks,
Chad
 
Upvote 0
Try

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Intersect(Target, Range("A3:F5")) Is Nothing Then Exit Sub
Application.EnableEvents = False
Select Case Target.Value
    Case "x": Target.ClearContents
    Case "": Target.Value = "x"
End Select
Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,706
Members
452,939
Latest member
WCrawford

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