I have four radio buttons on a worksheet each set to run a certain routine. When I click on a button the first time everything works fine. The routine filters a list of data. However, if new data is added to the list and I click on the same radio button a second time to refilter the list, it fails to do anything and the focus stays on the button instead of returning to the worksheet. What is causing this and how do I fix it? The code for one of the buttons in question is below
Private Sub OSButton_Click()
Call OSChecks
End Sub
Sub OSChecks()
Dim cell1 As Range
Dim rowcount As Integer
Dim myrng As Range
Set cell1 = Range("A6")
Set cell2 = Range("A5")
rowcount = Range(cell1, cell1.End(xlDown)).Rows.Count
Set myrng = Range(cell1.Offset(0, 9), cell1(rowcount, 10))
With ActiveSheet
.AutoFilterMode = False
.Range(cell2, cell2.Offset(rowcount, 9)).AutoFilter
End With
On Error Resume Next
N = WorksheetFunction.VLookup("O/S", myrng, 1, 0)
If Err = 1004 Then
MsgBox "There are no outstanding checks"
Else
Selection.AutoFilter Field:=10
Selection.AutoFilter Field:=4, Criteria1:=""
End If
Err.Clear
On Error GoTo 0
Range("A4").Select
End Sub
Private Sub OSButton_Click()
Call OSChecks
End Sub
Sub OSChecks()
Dim cell1 As Range
Dim rowcount As Integer
Dim myrng As Range
Set cell1 = Range("A6")
Set cell2 = Range("A5")
rowcount = Range(cell1, cell1.End(xlDown)).Rows.Count
Set myrng = Range(cell1.Offset(0, 9), cell1(rowcount, 10))
With ActiveSheet
.AutoFilterMode = False
.Range(cell2, cell2.Offset(rowcount, 9)).AutoFilter
End With
On Error Resume Next
N = WorksheetFunction.VLookup("O/S", myrng, 1, 0)
If Err = 1004 Then
MsgBox "There are no outstanding checks"
Else
Selection.AutoFilter Field:=10
Selection.AutoFilter Field:=4, Criteria1:=""
End If
Err.Clear
On Error GoTo 0
Range("A4").Select
End Sub