Question : VBA Excel Target & Intersect

Hi All,

I have a little proc that runs on a change in the worksheet in front of it, but it's behaving badly.
The proc allows the user to place a checkmark in Column A when clicking a cell in that column or moving the cursor there via the keyboard.  There are a couple of problems with it:

1) If the user selects the entire row, the contents are deleted.
2) It does not play well with Filters.

If you see a glaring issue or have a better way to provide this ability, let me know.
Thank you!

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'
    Dim p As Integer
    Dim r As Range

    p = Cells(Rows.count, "B").End(xlUp).Row
    Set r = Range("A4:A" & p)
   
    If Not Intersect(Target, r) Is Nothing Then
        If Target.Text = "a" Then
            Target.Value = ""
        Else
            Target.Value = "a"
        End If
    End If
'
End Sub

Answer : VBA Excel Target & Intersect

I think all you need is this small change.  I don't see anything immediately, that would act eradicately if a filter was in use.

Tom.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'
    Dim p As Integer
    Dim r As Range

    p = Cells(Rows.count, "B").End(xlUp).Row
    Set r = Range("A4:A" & p)
    
    If Not Intersect(Target, r) Is Nothing Then
        If Target.cells(1,1).value = "a" Then
            Target.cells(1,1).value = ""
        Else
            Target.cells(1,1).value = "a"
        End If
    End If
'
End Sub
Random Solutions  
 
programming4us programming4us