Alternate between two characters by selecting
Results 1 to 3 of 3

Thread: Alternate between two characters by selecting
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Jul 2018
    Posts
    8
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Alternate between two characters by selecting

    Hi all,
    I found this code to alternate between two characters (I use it to go around the autofill checkbox problem) it works great except it changes all the cells in the column instead of just the selected cell.

    P.S. I'm a real noob in coding, so please be specific

    Code:
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    'Fake checkbox
        If Not Intersect(Target, Range("G:G")) Is Nothing Then
            If Target.Count > 1 Then Exit Sub
            If Target.Value = "¨" Then Target.Value = "=CHAR(254)" Else: Target.Value = "=CHAR(168)"
        End If
        
        'Column skip
        If Not Intersect(Target, [F:F]) Is Nothing Then
            If Target.Count > 1 Then Exit Sub
            Static sRg As Range
            Dim ColumnOffset As Integer
            With Target
                Application.EnableEvents = False
                If Not sRg Is Nothing Then
                    If sRg.Column < .Column Then
                        ColumnOffset = 2
                    ElseIf .Column <> 1 Then
                        ColumnOffset = -1
                    End If
                Else
                    ColumnOffset = 1
                End If
                .Offset(, ColumnOffset).Select
                        Application.EnableEvents = True
            End With
            Set sRg = ActiveCell
        End If
    
    
    End Sub

  2. #2
    Board Regular
    Join Date
    Nov 2008
    Location
    Netherlands
    Posts
    3,402
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Alternate between two characters by selecting

    This is a bit of obscure code.
    If you select a cell in column G then it will do a alternate charcter. (It should not do the complete column!)

    If you select a cell in column F for the first time it will select the neighboring cell in column G ( but it should not trigger the swap)
    If you select a cell in column F a next time, it will select the neighboring cell in column E.

    Do you need any of this last stuff (automatically changing the column)? Or just when you click in column G that it does the toggle action?
    Short Guide to Better VBA - Link: https://www.mrexcel.com/forum/showthread.php?t=712119

    Please use code tags around your code:
    [Code] Your code here... [/Code]




    Engelse lessen, persoonlijk en doelgericht. Dutch tuition tailor-made for you. https://Ennef.nl

    Wearable for people with panic attacks: sidjup https://sidjup.com

  3. #3
    New Member
    Join Date
    Jul 2018
    Posts
    8
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Alternate between two characters by selecting

    The ''Column Skip'' portion of the code is used to be able to use TAB to fill in all the information in the table without toggling the ''Checkbox''. it essentially skips over that column, so if you want to toggle the ''Checkbox'' you have to either click the column or press the left arrow until you select the ''Checkbox'' cell.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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