excelvba

ActiveX scroll button prevents use of arrow keys


I have added an ActiveX scroll button to my work sheet and its macro works fine. However, when I am done clicking up or down, I want the arrow keys to move to another cell, but in fact it seems to be linked to the ActiveX scroll.

So, I added a save current cell address, and then selected that cell after, thinking that would trigger the next cell. But it doesn't make a difference. Any ideas?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  
    If Target.Cells.CountLarge > 1 Or Target.Cells.Column > (10) Then Exit Sub
    
    If ActiveCell.Column > 1 Then
    Cells.Interior.ColorIndex = 0
    Dim r As Range
    Set r = Union(Cells(Target.Row, 1).Resize(, Target.Column), _
                      Cells(1, Target.Column).Resize(Target.Row))
    r.Interior.Color = RGB(230, 230, 230)
    Target.Interior.Color = RGB(255, 230, 230)
    Else
    Cells.Interior.ColorIndex = 0
    Target.Interior.Color = RGB(255, 230, 230)
    End If

    Dim C As Range
    Set C = ActiveCell

    If Target.Cells.Count > 1 Then Exit Sub
    If Intersect(Range("C3:G23"), Target) Is Nothing Then Exit Sub
    ActiveSheet.OLEObjects("SpinButton1").LinkedCell = Target.Address
 
    C.Select

End Sub

Solution

  • To solve this issue use the GotFocus event of the spin button.
    On the worksheet's code module object dropdown, select SpinButton1 and add from the events the GotFocus

    Private Sub SpinButton1_GotFocus()
    ActiveCell.Select
    
    End Sub
    
    

    After this, the selection will always returns to the activecell, after changing the value of the linked cell.