我的vba代码有问题。它似乎在F8中运行但在F5中不运行。当它在F5中运行时,无法识别项目(显示为item = nothing)。我已粘贴下面的代码。
Sub SlicerSelect()
'On Error Resume Next
Worksheets("Sheet3").Activate
'Dim cache As Excel.SlicerCache
Dim item As SlicerItem
Dim Eval_Cell As String
Offset_Cell = Sheets("Sheet3").Range("A18").Address
A = 1: AA = 0: AAA = 0
For A = 1 To 2
AA = AA + 1
If AA = 1 Then
Slicer_Name = "Slicer_Color"
ElseIf AA = 2 Then
Slicer_Name = "Slicer_Letter"
End If
'Set cache = ActiveWorkbook.SlicerCaches(Slicer_Name)
BB = 0
Do Until End_Switch = 1
AAA = AAA + 1: BB = BB + 1: Eval_Cell = Range(Offset_Cell).Offset(0, CStr(AAA))
If BB = 1 Then
'''
Else
For Each item In ThisWorkbook.SlicerCaches(Slicer_Name).SlicerItems
If item.Name = Eval_Cell Then
item.Selected = True
Else
item.Selected = False
End If
Next item
End If
If IsEmpty(Eval_Cell) Then End_Switch = 1
Stop
Loop
End_Switch = 0
Next A
End Sub