VBA:将可见单元格(已过滤)粘贴到同一行但另一列

VBA: Paste visible cells (filtered) into same rows but another column

我想知道如何将过滤后的数据粘贴到相同的对应行但另一列。

我在 Excel 中过滤了 Table,如下所示:

#Row    |      A      |     B
 1      |      foo    |  
 5      |      bar    | 
 8      |      fish   | 

现在我想将 A 列中的值粘贴到 B 中以保持行位置。

#Row    |     A       |     B
 1      |     foo     |     foo
 2      |             |
 3      |             | 
 4      |             |
 5      |     bar     |     bar 
 ...    |             |
 ...    |             |
 8      |    fish     |     fish

普通粘贴方法将值粘贴为连续的块。

last = db_ws.Rows(Rows.Count).End(xlUp).Row
db_ws.Range("A11:BC" & last).SpecialCells(xlCellTypeVisible).Copy
tgt_ws.Range("A11").PasteSpecial

感谢任何帮助。

代码片段:

Dim i as Long
last = db_ws.Rows(Rows.Count).End(xlUp).Row

For i = 11 to last
If db_ws.Range("A"& i).EntireRowHidden=False Then
    tgt_ws.Range("A"& i).Value = db_ws.Range("A" & i).Value
    tgt_ws.Range("B" & i).Value = db_ws.Range("A" & i).Value
End If
Next i

要完成此处的主题,请使用阵列解决方案。

count = -1 ' array has to start with 0

On Error GoTo errHndlr:
For Each cl In rng.SpecialCells(xlCellTypeVisible)
    count = count + 1
    ReDim Preserve arr(count)
    arr(count) = cl.Row
    Debug.Print cl.Row
Next cl
errHndlr:

For Each Item In arr
    db_ws.Cells(Int(Item), 55) = db_ws.Cells(Int(Item), 1).Value
Next Item