将选定的单元格复制并粘贴到整行,直到上面的列为空

时间:2016-11-11 13:34:10

标签: excel vba excel-vba macros

我正在尝试找到一种方法来复制第5行中的活动Cell,并将该值粘贴到该单元格,直到第4行为空。我有多个工作表名称,需要为所有工作表名称完成此操作。

With ThisWorkbook.Sheets(SheetName)
    Dim LastColumn As Integer
    Dim c2 As Integer
    c2 = 2
    LastColumn = .UsedRange.Columns.Count
    Do Until IsEmpty(.Cells(4, c2).Value)
        If .Cells(1, c2).Value = MonthSel And .Cells(4, c2).Value = WkSel Then
            .Cells(5, c2).Value = RControl
            .Cells(5, c2).copy
            If .Cells(5, c2).Value <> "" Then
                c2 = c2 + 1
                .Cells(5, c2).Paste
            End If
        End If
    Loop
End With

我使用的sample数据。

How to results should look

如何结果应该看起来第5行应该用第5行的最新值

完全填充

1 个答案:

答案 0 :(得分:0)

根据我的想法,我从你的解释中理解,我想这就是你想要的。

<table align="center" border="0" width="100%" style="border:1px lightgray solid;box-shadow: 1px 2px 5px gray;margin-top:15px">
<tbody>
<tr>   

<!-- LEFT IMAGE-->
<td width="50%" valign="middle" style="text-align:justify;border-top: white 10px solid;border-bottom: white 10px solid;border-left: white 10px solid">
<div style="text-align: center;margin-bottom:0px">
<img style="WIDTH: 100%" src="http://www.allcarbrandslist.com/wp-content/uploads/2015/03/mustang-symbol.jpg" >
</div>
</td>

<!-- RIGHT TEXT -->
<td width="50%" valign="middle" style="text-align:justify;padding:3%;vertical-align:middle;color: gray;border: white 10px solid; background: linear-gradient(#F7F7F7 90%, #EDEDED 100%)">
<h2 style="color:black">Random Section header</h2>
<p>RANDOM TEST PARAGRAPH: A ruler frowns a built slogan. The toy copyrights a fruit on top of the verbatim commentator. A fond mania disciplines the increased finger. The prejudice founds a warped capitalist. Will the crossing grandmother bite the dismal prophet?</p>
</td>

</tr>
</tbody>
</table>