สอบถามการใช้ Public Function Custom
Posted: Sat Jul 21, 2018 7:11 pm
https://www.jkp-ads.com/articles/slicers05.asp
จากลิ้งนี้
เราจะเรียกใช้ Formula ใน VBA อย่างไรครับ =GetSelectedSlicerItems("Slicer_TeamID2") เนื่องจากว่า Code ดังกล่าวเหมือนมีการสร้างคำสั่งขึ้นมาใหม่ใน VBA ทำให้ติด Error ครับ
ตอนนี้ผ่านและ แต่ว่าทำไม ผลลัพธ์เป็น True อยากให้แสดงค่าดังกล่าวทำอย่างไรครับ
จากลิ้งนี้
Code: Select all
Public Function GetSelectedSlicerItems(SlicerName As String) As String
Dim oSc As SlicerCache
Dim oSi As SlicerItem
Dim lCt As Long
On Error Resume Next
Application.Volatile
Set oSc = ThisWorkbook.SlicerCaches(SlicerName)
If Not oSc Is Nothing Then
For Each oSi In oSc.SlicerItems
If oSi.Selected Then
GetSelectedSlicerItems = GetSelectedSlicerItems & oSi.Name & ", "
lCt = lCt + 1
End If
Next
If Len(GetSelectedSlicerItems) > 0 Then
If lCt = oSc.SlicerItems.Count Then
GetSelectedSlicerItems = "All Items"
Else
GetSelectedSlicerItems = Left(GetSelectedSlicerItems, Len(GetSelectedSlicerItems) - 2)
End If
Else
GetSelectedSlicerItems = "No items selected"
End If
Else
GetSelectedSlicerItems = "No slicer with name '" & SlicerName & "' was found"
End If
End FunctionCode: Select all
ActiveCell.FormulaR1C1 = "=GetSelectedSlicerItems(""Slicer_TeamID2"")"