+ Reply to Thread
Results 1 to 4 of 4

Check and uncheck without leaving the cell

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-03-2012
    Location
    USA
    MS-Off Ver
    2010
    Posts
    496

    Check and uncheck without leaving the cell

    Hello,
    Attached is a sample to add and delete "X" from a cell. The problem
    is after a single click to add "X", to delete "X", the mouse pointer needs
    to leave the cell then come back to cell to delete. I would like to add and delete
    "X" by toggle the mouse without leaving the cell.

    Thanks
    Last edited by Rocky2013; 02-27-2014 at 08:50 AM.

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Check and uncheck without leaving the cell

    I changed it to double click event...

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    
    If Intersect(Range("C1:C10"), Target) Is Nothing Then Exit Sub
    If Target.Count <> 1 Then Exit Sub
    
    If Target.Value = "" Then
      Target.Value = "X"
    Else
      Target.Value = ""
    End If
    
    Cancel = True
    
    End Sub


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,240

    Re: Check and uncheck without leaving the cell

    Hi Rocky,

    I like to use the double click event better for this type of X or not X. My normal is to double click in Column A with this code:
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
        If Target.Column <> 1 Then GoTo Ender
        If Target.Row = 1 Then GoTo Ender
        If Target = "x" Then
                Target = ""
        GoTo Ender
        End If
        If Target = "" Then
                Target = "x"
        End If
    Ender:
        Cancel = True
    End Sub
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Forum Contributor
    Join Date
    10-03-2012
    Location
    USA
    MS-Off Ver
    2010
    Posts
    496

    Re: Check and uncheck without leaving the cell

    Thanks! Both codes work. I more I try, I think double click is better to avoid mistake
    when click a cell.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA help with check and uncheck
    By akajj13 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-23-2013, 01:02 AM
  2. Macro to automatically check or uncheck checkboxes based on a linked cell
    By lmshow in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-19-2013, 03:31 AM
  3. Can't Check / Uncheck Chechbox based on Cell value because of PasteSpecial
    By Saramara in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-29-2011, 09:13 AM
  4. Uncheck a Check Box using VBA
    By ashmott in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-01-2011, 10:29 PM
  5. Replies: 5
    Last Post: 01-04-2006, 07:15 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1