如何计算 Excel 中过滤后的 table,可能使用 VBA

How to calculate off a filtered table in Excel, possibly use VBA

这里是全新的 VBA 用户:

我正在尝试从 excel 中过滤的 table 计算出 table 表格。我知道过滤后的 table 只隐藏值,所以做任何偏移或索引仍然 returns 隐藏过滤后的值,所以互联网促使我使用 VBA。

在使用 VBA 时,我似乎无法将变量插入 range.value 中,该变量在每个循环中增长,因此单元格会增长,直到可见过滤 table 完成。我相信 Do Until 函数是我应该用来实现此目的的函数,但我的代码需要一些主要帮助,或者我不知道更简单的过程:

当前损坏的代码:

Sub TableCreate()

iRow = 1

iPlug = 1

Do Until IsEmpty(Cells(iRow, 1))

Set Rng = Range("A"iPlug)

' Store the current cell value in the dCellValues array

Range(Rng).Value = Cells(iRow, 1).Value

iRow = iRow + 1

iPlug = iPlug + 1

Loop


End Sub

谢谢,

EEE

如果要在单元格地址中使用数字变量,则必须将数字与符号 & 连接起来。

Set Rng = Range("A" & iPlug)

看起来你只需要一个变量,因为 iPlug 和 iRow 将始终是相同的值。

如果将Rng变量声明为范围,则可以直接使用该变量。

    Dim Rng as Range
'... code leading up to this ...
    Set Rng = Range("A"&iPlug)

    ' Store the current cell value in the dCellValues array

    Rng = Cells(iRow, 1).Value

您也可以直接使用 Range 方法,而不使用变量。

Range("A"&iPlug) = Cells(iRow, 1).Value