Alternate between two characters by selecting

Chuckarou

New Member
Joined
Jul 12, 2018
Messages
19
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
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
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?
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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