Excel数据透视图:显示最后25行

Excel数据透视图:显示最后25行,excel,vba,pivot-table,pivot-chart,Excel,Vba,Pivot Table,Pivot Chart,我有一组数据,我有一个宏运行,每5秒添加一行 它链接到仪表板中的数据透视表和数据透视图 (图为我的第二个版本,增量而非递减) 我在一个隐藏页面中有一个字段,我在其中输入了我想要查看的最后记录行的数量 例如,我有1000行,我想要仪表板图形,按下一个按钮,在“只查看最后一个X”或“查看全部”之间切换 我想找到一种更轻松的方式来完成我所做的事情,因为我看到了很大的延迟 为此,我在数据中添加了两列,其中包含一个宏写入公式 列D:为该行指定一个值 列E:如果D的值大于0,则写“最后一个X日志”,其余写

我有一组数据,我有一个宏运行,每5秒添加一行 它链接到仪表板中的数据透视表和数据透视图

(图为我的第二个版本,增量而非递减)

我在一个隐藏页面中有一个字段,我在其中输入了我想要查看的最后记录行的数量

例如,我有1000行,我想要仪表板图形,按下一个按钮,在“只查看最后一个X”或“查看全部”之间切换

我想找到一种更轻松的方式来完成我所做的事情,因为我看到了很大的延迟


为此,我在数据中添加了两列,其中包含一个宏写入公式

列D:为该行指定一个值

列E:如果D的值大于0,则写“最后一个X日志”,其余写“在X日志之前”


我把这个代码放在D列

设置!I4=字段,其中i为需要的日志数量Ex;十五

设置!I5=是我存储公式中要使用的最后一行值的位置,从而更新每个添加行的所有行

setsheet.Range("I5").Value = lastrow

logsheet.Range("D" & lastfreerow).Value = ("=Settings!I4-(Settings!I5)") & "+" & setsheet.Range("I5").Text
将公式写入单元格,如下所示:

=Settings!I4-(Settings!I5)+7
=IF(D8>0;"Last" & " " & Settings!I$4 & " logs";"Before the last" & " " & Settings!I$4 & " logs")
结果是倒计时,其中最新值为“15” 而最老的是否定的


把这个代码放在E列

logsheet.Range("E" & lastfreerow).Value = "=IF(RC[-1]>0,""Last"" & "" "" & Settings!R4C[4] & "" logs"",""Before the last"" & "" "" & Settings!R4C[4] & "" logs"")"

将公式写入单元格,如下所示:

=Settings!I4-(Settings!I5)+7
=IF(D8>0;"Last" & " " & Settings!I$4 & " logs";"Before the last" & " " & Settings!I$4 & " logs")
我在切片器中使用这些“值”对数据透视表进行排序


谢谢

这是我简化的版本,因为每个周期只有一列有更新公式。但是我没有看到宏的负载有多大的改善

之前

        'Create the IF formula that will give a value to the row, the older the row the smaller the value
setsheet.Range("I5").Value = lastrow

logsheet.Range("D" & lastfreerow).Value = ("=Settings!I4-(Settings!I5)") & "+" & setsheet.Range("I5").Text

        'Create the IF formula that will say if the row is part of the desired range for the "last logs" option
logsheet.Range("E" & lastfreerow).Value = "=IF(RC[-1]>0,""Last"" & "" "" & Settings!R4C[4] & "" logs"",""Before the last"" & "" "" & Settings!R4C[4] & "" logs"")"

之后

        'Log#; simply give an incremental value to each row starting from 1
            setsheet.Range("I6").Value = lastrow - 6                                            'Row value of the last log, put into the hidden setting page to be used in a formula
            logsheet.Range("D" & lastfreerow).Value = (lastrow - 6)                             'Row value of the last log,

        'Create the IF formula that will say if the row is part of the desired range for the "last logs" option
            logsheet.Range("E" & lastfreerow).Value = "=IF((Settings!R6C9 - Settings!R4C9) < (Log!RC[-1]),""Last"" & "" "" & Settings!R4C9 & "" logs"",""Before the last"" & "" "" & Settings!R4C9 & "" logs"")"

日志#;只需从1开始为每行提供一个增量值
setsheet.Range(“I6”).Value=lastrow-6'最后一个日志的行值,放入隐藏的设置页,用于公式中
最后一个日志的logsheet.Range(“D”和lastfreerow).Value=(lastrow-6)行值,
'创建IF公式,该公式将说明该行是否属于“last logs”选项所需范围的一部分
logsheet.Range(“E”和lastfreerow).Value=“=IF((设置!R6C9-Settings!R4C9)<(Log!RC[-1]),“Last”“和”“设置!R4C9和”“日志”“在最后一个”“和”“设置!R4C9和”“日志”“之前)”
如果您有什么想法,可以用图表只显示最后的X值的方式对表格进行排序,我会感兴趣的


谢谢你抽出时间

这是我的版本,有点简化,因为每个周期只有一列有更新公式。但是我没有看到宏的负载有多大的改善

之前

        'Create the IF formula that will give a value to the row, the older the row the smaller the value
setsheet.Range("I5").Value = lastrow

logsheet.Range("D" & lastfreerow).Value = ("=Settings!I4-(Settings!I5)") & "+" & setsheet.Range("I5").Text

        'Create the IF formula that will say if the row is part of the desired range for the "last logs" option
logsheet.Range("E" & lastfreerow).Value = "=IF(RC[-1]>0,""Last"" & "" "" & Settings!R4C[4] & "" logs"",""Before the last"" & "" "" & Settings!R4C[4] & "" logs"")"

之后

        'Log#; simply give an incremental value to each row starting from 1
            setsheet.Range("I6").Value = lastrow - 6                                            'Row value of the last log, put into the hidden setting page to be used in a formula
            logsheet.Range("D" & lastfreerow).Value = (lastrow - 6)                             'Row value of the last log,

        'Create the IF formula that will say if the row is part of the desired range for the "last logs" option
            logsheet.Range("E" & lastfreerow).Value = "=IF((Settings!R6C9 - Settings!R4C9) < (Log!RC[-1]),""Last"" & "" "" & Settings!R4C9 & "" logs"",""Before the last"" & "" "" & Settings!R4C9 & "" logs"")"

日志#;只需从1开始为每行提供一个增量值
setsheet.Range(“I6”).Value=lastrow-6'最后一个日志的行值,放入隐藏的设置页,用于公式中
最后一个日志的logsheet.Range(“D”和lastfreerow).Value=(lastrow-6)行值,
'创建IF公式,该公式将说明该行是否属于“last logs”选项所需范围的一部分
logsheet.Range(“E”和lastfreerow).Value=“=IF((设置!R6C9-Settings!R4C9)<(Log!RC[-1]),“Last”“和”“设置!R4C9和”“日志”“在最后一个”“和”“设置!R4C9和”“日志”“之前)”
如果您有什么想法,可以用图表只显示最后的X值的方式对表格进行排序,我会感兴趣的


谢谢你抽出时间

粘贴完整的代码和一些示例数据,否则很难说如何改进粘贴完整的代码和一些示例数据,否则很难说如何改进