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

时间:2019-04-04 13:04:42

标签: excel vba filter copy paste

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

我在Excel中有一个经过过滤的表格,如下所示:

#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

任何帮助表示赞赏。

2 个答案:

答案 0 :(得分:1)

代码段:

<?php
if(isset($_POST['email'])) {
    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "myemail@example.com";
    $email_subject = "Your email subject line";

    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }
    // validation expected data exists
    if(!isset($_POST['first_name']) ||
       !isset($_POST['last_name']) ||
       !isset($_POST['Country']) ||
       !isset($_POST['email']) ||
       !isset($_POST['address']) ||
       !isset($_POST['phone']) ||
       !isset($_POST['adults']) ||
       !isset($_POST['kids']) ||
       !isset($_POST['arrive_date']) ||
       !isset($_POST['arrive_time']) ||
       !isset($_POST['departure_date']) ||
       !isset($_POST['departure_time']) ||
       {
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }

答案 1 :(得分:1)

为完成本主题,您将使用阵列解决方案。

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