VBAnoob_Corina
New Member
- Joined
- Apr 17, 2014
- Messages
- 13
Hello everybody,
I have a very stubborn problem and I can't figure it out on my own. I hope somebody can help me out. In order to filter some columns in a certain worksheet, I have designed another sheet with shapes which represent the rough structure. The shapes switch colors when clicked on and also set filters. Currently the filters are set independently from each other, meaning that my result just adds the criteria up. I'm not quite sure how to describe it. But what I want is an intersecting result... This is what I wrote so far (it's not elegant at all, I'm an absolute beginner):
I also tried playing around with the operators, but it didn't work out -.- To sum it up, I would like to preserve the criteria I already set for one column when filtering another column. Also, if you have an idea how to simplify the whole code, I'd be really grateful. Thank you very much for your support! Hope you can help...
I wish you all a great day.
Kind regards,
VBAnoob_Corina
I have a very stubborn problem and I can't figure it out on my own. I hope somebody can help me out. In order to filter some columns in a certain worksheet, I have designed another sheet with shapes which represent the rough structure. The shapes switch colors when clicked on and also set filters. Currently the filters are set independently from each other, meaning that my result just adds the criteria up. I'm not quite sure how to describe it. But what I want is an intersecting result... This is what I wrote so far (it's not elegant at all, I'm an absolute beginner):
Code:
Private myText As String
Sub RoundedRectangle_Click()
'On click filter listed categories in "Risk Category Checklist" by the text in the rounded rectangles
Dim ws As Excel.Worksheet
Dim shp As Shape
Dim CritArr()
Dim a As Integer
Dim B As Integer
Dim c As Integer
Set ws = Worksheets("Risk Category Checklist")
Set shp = ActiveSheet.Shapes(Application.Caller)
ToggleShapeColor
Application.ScreenUpdating = False
For Each shp In ActiveSheet.Shapes
With shp
If .Fill.ForeColor.RGB = RGB(0, 176, 80) Then
Select Case myText
Case "Internal", "External", "Combination"
ReDim Preserve CritArr(a)
CritArr(a) = .TextFrame2.TextRange.Characters.Text
a = a + 1
Case "Financial", "Infrastructure", "Reputational", "Market"
ReDim Preserve CritArr(B)
CritArr(B) = .TextFrame2.TextRange.Characters.Text
B = B + 1
Case "Strategic", "Project-related", "Operational"
ReDim Preserve CritArr(c)
CritArr(c) = .TextFrame2.TextRange.Characters.Text
c = c + 1
End Select
End If
End With
Next shp
If a <> 0 Then
ws.Range("$A$5:$W$500").AutoFilter , Field:=4, Criteria1:=CritArr, Operator:=xlFilterValues
Else
ws.Range("$A$5:$W$500").AutoFilter , Field:=4
End If
If B <> 0 Then
ws.Range("$A$5:$W$500").AutoFilter , Field:=6, Criteria1:=CritArr, Operator:=xlFilterValues
Else
ws.Range("$A$5:$W$500").AutoFilter , Field:=6
End If
If c <> 0 Then
ws.Range("$A$5:$W$500").AutoFilter , Field:=11, Criteria1:=CritArr, Operator:=xlFilterValues
Else
ws.Range("$A$5:$W$500").AutoFilter , Field:=11
End If
Application.ScreenUpdating = True
End Sub
Private Sub ToggleShapeColor()
'Change shape color on click in sheet "Checklist Structure"
Dim shp As Shape
Set shp = ActiveSheet.Shapes(Application.Caller)
myText = shp.TextFrame2.TextRange.Characters.Text
With shp
If .Fill.ForeColor = RGB(56, 93, 138) Then
.Fill.ForeColor.RGB = RGB(0, 176, 80)
Else
.Fill.ForeColor.RGB = RGB(56, 93, 138)
End If
End With
End Sub
I also tried playing around with the operators, but it didn't work out -.- To sum it up, I would like to preserve the criteria I already set for one column when filtering another column. Also, if you have an idea how to simplify the whole code, I'd be really grateful. Thank you very much for your support! Hope you can help...
I wish you all a great day.
Kind regards,
VBAnoob_Corina