2 SelectionChange on the same worksheet

Chuckarou

New Member
Joined
Jul 12, 2018
Messages
19
Hello all, I've found quite a lot of usefull tips on this forum by just looking around, but I can't seem to find this answer for this problem. Keep in mind that I have next to no knowledge in VBA of coding in general.

I have found two codes that I would like to use simultaneously on the same worksheet, but apparently I can't because they are both SelectionChange codes.

Here are the codes:

Code 1:

Private sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target,Range(“A:1”)) Is Nothing Then
If Target.Count > 1 Then Exit Sub
If Target.Value = “þ” Then Target.Value = “¨” Else: Target.Value = “þ”
End If
End Sub

Code 2:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Static sRg As Range
Dim ColumnOffset As Integer
If Target.Count > 1 Then Exit Sub
If Not Intersect(Target, Union([B:B], [D:D], [F:F])) Is Nothing Then
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
End If
Set sRg = ActiveCell
End Sub

Thanks in advance for anyone who has answers!
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Chuckarou,

You might consider the following...

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("A:1")) Is Nothing Then
    If Target.Count > 1 Then Exit Sub
    If Target.Value = "þ" Then Target.Value = "¨" Else: Target.Value = "þ"
End If

If Not Intersect(Target, Union([B:B], [D:D], [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

Cheers,

tonyyy
 
Upvote 0

Forum statistics

Threads
1,214,424
Messages
6,119,404
Members
448,893
Latest member
AtariBaby

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