1

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

看起来像这样(图片是我的第二个版本,增量而不是减量)

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

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

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


我通过在数据中添加两列并在其中添加宏写入公式来实现这一点

Col D : 给行赋值

Col E :如果 D > 0 的值写入“最后 X 个日志”,其余的写入“X 个日志之前”


我把这段代码放在 Col D

设置!I4 = 我想要的日志数量的字段;15

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

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

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

这在单元格中写入公式,如下所示:

=Settings!I4-(Settings!I5)+7

结果是倒计时,其中最近的值为“15”,最旧的值为负数


并将此代码用于 Col E

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

这在单元格中写入公式,如下所示:

=IF(D8>0;"Last" & " " & Settings!I$4 & " logs";"Before the last" & " " & Settings!I$4 & " logs")

我在对我的数据透视表进行排序的切片器中使用那些“值”

谢谢你

4

1 回答 1

0

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

        '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"")"

如果您对以图表仅显示我感兴趣的最后 X 值的方式对表格进行排序的方法有任何想法

感谢您的时间!

于 2019-10-04T22:37:59.390 回答