Validation Tool Help

Courtney Ruggles

New Member
Joined
Jun 6, 2008
Messages
5
I am currently using the validation tool to limit the number of selections in column A of my worksheet to 3 or less (The selections are made using a double-click VB code). The formulat that I am using for the allowance criteria is: =COUNTIF($A$11:$A$10001,"a")<4. Currently, the formula and the limitation is working fine and the error box is popping up at the appropriate time (i.e. when the 4th selection is made). However, if I click "Cancel" in the Error box, the spreadsheet allows the 4th selection to remain. Is it possible to use VB code to force the 4th selection to be deleted once the error box pops up?

Thank you in advance for your time and help!! I appreciate it! :)
~CR
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Courtney

I don't really understand why the BeforeDoubleClick stops the validation working properly - but this code fixed it for me:

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If [countif( a11 : a10001, "a")<3] Then
    Target.Value = "a"
Else
    MsgBox "Only 3 selections are allowed"
    Cancel = True
End If
End Sub

You'll want to keep the cell validation too, in case anyone types the "a" directly into the cell.
 
Upvote 0
Thank you so much for your help!!

I added:

Target.Cell = Null

after the Cancel = True in order to clear the contents of the 4th selected cell and this worked perfectly! I really appreaciate your help! :) :)

Take Care,

~CR
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,243
Members
449,075
Latest member
staticfluids

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