-1
我正在使用VBA執行一個數據透視表字段的搜索,我希望能夠做一個基於字段是否包含字符串的一部分,但不確定如何做這個沒有檢查爲整體價值。波紋管是我目前擁有的:VBA字段包含
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'This line stops the worksheet updating on every change, it only updates when cell
'P4 is touched
If Intersect(Target, Range("B4")) Is Nothing Then Exit Sub
'Set the Variables to be used
Dim pt As PivotTable
Dim Field As PivotField
Dim NewPull As String
'Here you amend to suit your data
Set pt = Worksheets("Pull Code Search").PivotTables("PivotTable1")
Set Field = pt.PivotFields("Pull Code")
If IsEmpty(Range("B3").Value) = True Then
NewPull = "(All)"
Else
NewPull = Worksheets("Pull Code Search").Range("B3").Value
End If
'This updates and refreshes the PIVOT table
With pt
Field.ClearAllFilters
Field.CurrentPage = NewPull
If NewPull = "(All)" Then
ActiveSheet.PivotTables(1).PivotFields(1).ShowDetail = False
End If
pt.RefreshTable
End With
End Sub
FWIW'InStr函數'也有[Docs.SO專用主題](http://stackoverflow.com/documentation/vba/3480/searching-within-stri NGS-爲最存在-的子串#噸= 20161027203242050143)。 –
太好了。謝謝。 – Naidu
無法確定在這種情況下如何使用它。 –