VBA running in F8 but not in F5

Deen444

New Member
Joined
Jan 27, 2018
Messages
2
Hello,

I am having some trouble with my vba code. It seems to work in f8 but not when I run it in f5. When I run it in f5 the item is not recognized and equals nothing.
I have pasted the code below.



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

'Row_start = Worksheets("Sheet3").Range("B1").End(xlDown).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
' Eval_Cell.Select
'cache.VisibleSlicerItems(item.Name).Selected = Eval_Cell.Selected
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



Thanks,
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
What item is not recognized? What line of code is highlighted when the code halts? What error message do you get?
 
Upvote 0
It's this part of the code:

For Each item In ThisWorkbook.SlicerCaches(Slicer_Name).SlicerItems

If item.Name = Eval_Cell Then

I don't get an error message. The code runs through but it doesn't work to filter my slicer. When I run the code and I hover over item, it shows that item = nothing.

But when I run it in f8 item actually equals the items in the slicer as it loops through and it works.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top