Excel VBA将变量传递给数据透视表参数

时间:2015-07-22 23:09:46

标签: excel excel-vba vba

嗨大家我想将变量传递给数据透视表的值过滤器。我正在尝试下面的代码,但它给了我错误。有什么建议。我正在尝试将x varibale放入Value1

<div id="main" class="container">
<div class="page-header">
     <h3 class="text-info">
     Training Summary <small>Schedule Breakdown</small> 
     <span class="pull-right">
        <div class="input-prepend input-append">
           <button tabindex="-1" data-toggle="dropdown" class="btn dropdown-toggle">
           Start Date&nbsp;&nbsp; <span class="caret"></span>
           </button>
           <ul class="dropdown-menu">
              <li><a href="#">Action</a></li>
              <li><a href="#">Another action</a></li>
              <li><a href="#">Something else here</a></li>
              <li class="divider"></li>
              <li><a href="#">Separated link</a></li>
           </ul>
           <input class="span2 dp cen" type="text" placeholder="Select a Start Date" name="startDate">
           <button tabindex="-1" data-toggle="dropdown" class="btn dropdown-toggle">
           End Date&nbsp;&nbsp;<span class="caret"></span>
           </button>
           <ul class="dropdown-menu">
              <li><a href="#">Action</a></li>
              <li><a href="#">Another action</a></li>
              <li><a href="#">Something else here</a></li>
              <li class="divider"></li>
              <li><a href="#">Separated link</a></li>
           </ul>
           <input class="span2 dp cen" type="text" placeholder="Select an End Date" name="endDate">
           <button class="btn" type="button" name="fetch"><i class="icon-refresh"></i></button>
        </div>
     </span>
  </h3>
</div>

1 个答案:

答案 0 :(得分:1)

这是一个错字吗? (PivoJtFields)。并确保您在带有数据透视表的工作表上,并且表格具有正确的名称。

尝试

x = "*" + Range("Sheet1!h17").Value + "*"

Dim PT As PivotTable
Set PT = ActiveSheet.PivotTables("PivotTable2")

Dim PT_PivotFieldNote As PivotField
Set PT_PivotFieldNote = PT.PivotFields("Note")

PT_PivotFieldNote.ClearAllFilters
PT_PivotFieldNote.PivotFilters.Add xlCaptionContains, Value1:=x