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
 

Some videos you may like

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

sijpie

Well-known Member
Joined
Nov 1, 2008
Messages
3,661
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?
 

Chuckarou

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

Watch MrExcel Video

Forum statistics

Threads
1,101,946
Messages
5,483,831
Members
407,415
Latest member
Anton1999

This Week's Hot Topics

  • Finding issue in If elseif else with For each Loop
    Finding issue in If elseif else with For each Loop I have tried this below code but i'm getting in Y column filled with W005. Colud you please...
  • MsgBox Error
    Hi Guys, I have the below error show up when i try and run my macro in File1 but works fine if i copy and paste the same code into file2. [ATTACH...
  • CELL FORMAT - IF CONDITION
    My Cell Format is [B]""0.00" Cr". [/B]But in the cell, it is showing 123.00 for editing. (123 is entry figure). (Data imported from other...
  • Show numbers nearly the same
    Is this possible. I have a number that can change very time eg 0.00001234 Then I have a lot of numbers 0.0000001, 0.0000002, 0.00000004...
  • Please i need your help to create formula
    I need a formula in cell B8 to do this >>if b1=1 then multiply ( cell b8) by 10% ,if b1=2 multiply by 20%,if=3 multiply by 30%. Thank you in...
  • Got error while adding column and filter
    Got error while adding column and filter In column Z has some like "Success" and "Error". I want to add column in AA if the Z cell value is...
Top