在枢轴项目格式中以相同的格式制作一个字符串日期
我有一个具有起点条件的枢轴表是类似的。
而且我已经有一个数组作为rgtglval变量,如果我使用此代码循环到rgtglval的每个项目时,rgtglval中的每个el next 当地窗口中的el el值如下:#044 -Jun-2022#,#10-Jun-2022#等等。
基于数组的每个值,我想通过抵消TGL列中的枢轴项目的标签来选择NOTA字段的范围。
For Each el In rgTglVal
With pt.PivotFields("TGL")
X = Format(el, "dd-mmm-yy")
X = Replace(X, "-", "/") '--> this give me a string value in the kind "dd/mmm/yy"
.PivotItems(X).LabelRange.Offset(0, 2).Select 'expected final result
End With
Next
该代码可以按预期工作,因为在我编写上面的代码之前,我首先检查使用这种代码在tgl字段中格式化的值:pt. -pivotfields(“ tgl”)。 PivotItems:退出:Next
,因此我可以看到PIT String值就像“ 19/Mar/14”。因此,它的格式为“ dd/mmm/yy”中的文本。
我的问题:
将RGTGLVAL中的EL值作为TGL字段中枢轴项目的值,如何获得预期的最终结果,而无需手动了解TGL字段的枢轴项目格式化的格式?
任何形式的反应都将不胜感激。
谢谢您。
我将问题缩短,但是看来我的读者也很难理解。
假设TGL列不是日期,而是字符串... AAA,BBB,CCC,DDD等。因此,如果我想获取枢轴项目为AAA的nota范围,我可以使用:pt.pivotfields(“ tgl”)。pivotitems(“ aaa”)。labelRange.Offset.Offset.offset(0,2) .select
- >这将选择NOTA PB220520029和PB-220521003范围。
如果我想要枢轴项目为bbb的nota范围,我只能做 pt.pivotfields(“ tgl”)。pivotitems(“ bbb”)。labelrange.offset(0,2).select
- >这将选择NOTA PB220524026,PB-220528029和PB-220531038。
等等。
但是,由于TGL字段数据是日期,pt.pivotfields(“ tgl”)。pivotitems(#04-Jun-22#)。labelrange.offset.offset(0,2).select
无法正常工作,因为据我所知,枢纽需要是一个字符串。 #04-Jun-22#是日期,rgtglval数组的EL值。
即使我将其转换为字符串,也这样: pt.pivotfields(“ tgl”)。pivotitems(格式(#6/4/22#,“ dd-mmm-yy”))。labelrange.offset(0,2).select
它可以工作 - 它可能行不通,因为枢轴项目的字符串可能“ dd-mmm-yy”,也许是“ dd/mmm/yy”等,取决于如何在枢轴字段中设置TGL字段的数字格式设置--->因此,这是因为我不知道如何进行编码,因此自动将EL值(日期)调整到该应用程序格式的任何模型。
我唯一能够知道该应用程序为日期枢轴项目格式的唯一一件事是逐步运行pt.pivotfields(“ tgl”)的每个坑。 >然后查看手动如何在当地窗口中格式化坑值。
只有在i 手动之后,请参见当地窗口中的循环坑值,例如(例如)“ 19/mar/14”。因此,我知道我应该这样做的代码:pt.pivotfields(“ tgl”)。pivotitems(格式(el,“ dd/mmm/yy”))。labelrange.offset.offset(0,2)。选择
I have a pivot table with a beginning condition is something like that.
And I already have an array as rgTglval variable, when if I looped to each item of rgTglVal with this code For Each el In rgTglVal: next
the value of el in the Locals Window is like this : #04-Jun-2022#, #10-Jun-2022# and so on.
Based on each value of the array, I want to select the range of NOTA field by offseting the labelrange of the pivot items in TGL column.
For Each el In rgTglVal
With pt.PivotFields("TGL")
X = Format(el, "dd-mmm-yy")
X = Replace(X, "-", "/") '--> this give me a string value in the kind "dd/mmm/yy"
.PivotItems(X).LabelRange.Offset(0, 2).Select 'expected final result
End With
Next
The code works as expected because before I wrote the code above, I check first how the value of pivot item in TGL field is formatted by using this kind of code : For Each pit In pt.PivotFields("TGL").PivotItems: Exit For: Next
so I can see the pit string value is like this "19/Mar/14". So it's formatted as text in the kind "dd/mmm/yy".
My question :
Using the el value from rgTglVal as the value of the pivot items in TGL field, how do I get the expected final result without the need to know manually on how the pivot items of the TGL field is formatted ?
Any kind of respond would be greatly appreciated.
Thank you in advanced.
I make the question shorter, but it seems it still difficult to be understodd by my reader.
Assumed that the column TGL is not a date but a string... aaa, bbb, ccc, ddd and so on. So if I want to get the range of NOTA where the pivot item is aaa, I can just do with : pt.pivotfields("TGL").pivotitems("aaa").labelrange.offset(0,2).select
--> this will select nota PB220520029 and PB-220521003 range.
and if I want the range of NOTA where the pivot item is bbb, I can just do withpt.pivotfields("TGL").pivotitems("bbb").labelrange.offset(0,2).select
--> this will select nota PB220524026, PB-220528029 and PB-220531038.
and so on.
But since the TGL field data are dates, pt.pivotfields("TGL").pivotitems(#04-Jun-22#).labelrange.offset(0,2).select
won't work, because as long as I know, the pivotitems need to be a string. #04-Jun-22# is a date, the el value of the rgTglVal array.
Even if I convert it to string, like this :pt.pivotfields("TGL").pivotitems(format(#6/4/22#, "dd-mmm-yy")).labelrange.offset(0,2).select
it may work - it may not work, because the string of the pivot items maybe "dd-mmm-yy", it maybe "dd/mmm/yy", etc depends on how the number format of the TGL field is set in the pivot field setting ---> so this is because I don't know on how to code so it automatically adjust the el value (a date) to whatever model of the pivot items string is formatted by the app.
The only thing I am able to know how the string is formatted for the date pivot item by the app is by step run For Each pit In pt.PivotFields("TGL").PivotItems: Exit For: Next
then see manually how the pit value is formatted in the Locals Window.
Only after I manually see the looped pit value in the Locals Window is (for example) like this "19/Mar/14". So then I know that I should do the code like this : pt.pivotfields("TGL").pivotitems(format(el, "dd/mmm/yy")).labelrange.offset(0,2).select
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论