我想每天将工作表名称更改为今天的日期。
Sub GetPivotData()
Dim sToday As String
sToday = Format(Date, "dd.mm.yy")
Range("C2").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(GETPIVOTDATA(""Opportunity"",'28.06.16'!R34C28,""Status"",""Open"",""Probability"",20,""Sales Territory"",R[2]C[6]),0)"
Range("C3").Select
End Sub
我想将'28 .06.16'更改为'今天'。
答案 0 :(得分:2)
将变量连接到公式字符串中。
Option Explicit
Sub GetPivotData()
Dim sToday As String
sToday = Format(Date, "dd.mm.yy")
With Worksheets("Sheet1") '<~~ you should know what worksheet you are on!
.Range("C2").FormulaR1C1 = _
"=IFERROR(GETPIVOTDATA(""Opportunity"",'" & sToday & "'!R34C28,""Status"",""Open"",""Probability"",20,""Sales Territory"",R[2]C[6]),0)"
End With
End Sub
答案 1 :(得分:0)
试试这个:
Application.workbooks(&#34; YourWorkbook&#34;)。sheet(&#34; YourSheetname&#34;)。name = sToday