Thanks and apologies for being not precise. The cause of the B2 change is a formula.
In the meantime I could harmonize some parts of the sheet. For calculation purposes I still need the number system but my choice field can contain "aaa + bbb", "aaa" and "bbb". So maybe the code can be adapted so that it doesn't need the numbers anymore.
The updated example 3 contains the same adapted data in sheets 1 and 2 and different VBA code
Sheet 1:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim lSelection As Long, stFilter As String
If Target = Range("B3") Then
lSelection = Range("B3")
Select Case lSelection
Case Is = 1
stFilter = "*"
Case Is = 2
stFilter = "aaa"
Case Is = 3
stFilter = "bbb"
Case Else
'default code
End Select
ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=1, Criteria1:=stFilter
End If
End Sub
Sheet 2:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim lSelection As Long, stFilter As String
If Target = Range("B2") Then
lSelection = Range("B2")
Select Case lSelection
Case Is = "aaa + bbb"
stFilter = "*"
Case Is = "aaa"
stFilter = "aaa"
Case Is = "bbb"
stFilter = "bbb"
Case Else
'default code
End Select
ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=1, Criteria1:=stFilter
End If
End Sub
But somehow it doesn't work on sheet 2 when I enter "aaa + bbb" instead of 1 ....
Still I am aiming the same - but it doesn't matter anymore if the filter is caused by the change of a number or text.
Your help is greatly appreciated.
Bookmarks