2016-10-27 8 views
-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 

答えて

1

INSTRを使用してください。

この関数は、文字列内のサブストリングの最初の発生の位置を返します。文字列全体をループする必要はありません。

文字列(サブ)のあなたの部分は、実際の「文字列」に存在する場合、この関数は正の値を返します。ここでは、 "INSTR関数は、Microsoft ExcelでVBAコードでのみ使用することができ"

構文

InStr([start], string, substring, [compare]) 

詳しい説明:

https://www.techonthenet.com/excel/formulas/instr.php

+0

FWIW 'InStr関数'また【Docs.SO上の専用トピック]を有する(http://stackoverflow.com/documentation/vba/3480/searching-within-stri部分文字列の存在のためには、n ts = 20161027203242050143)。 –

+0

ありがとうございました。 – Naidu

+0

このインスタンスでの使用方法の決定に問題があります。あなたのコード内で使用すると、正確な文字列値を探しているところ –

関連する問題