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

我正在尝试find一种方法来复制第5行中的活动单元格,并将该值粘贴到该单元格中,直到第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 

我正在使用的数据的一个示例 。

应该看看结果如何

如何结果应该看起来像第5行应该完全填写第5行的最新值

从我认为我从你的解释中了解到,我想这就是你想要的。

  Dim LastColumn As Integer Dim c2 As Integer Dim SourceCell As Range With ThisWorkbook.Sheets(SheetName) 'get last used column in row 4, ALTHOUGH THIS IS NOT NEEDED IN THIS CODE LastColumn = .Cells(4, .Columns.Count).End(xlToLeft).Column 'loop through rest of the row c2 = 2 Do Until IsEmpty(.Cells(4, c2).Value) If .Cells(1, c2).Value = MonthSel And .Cells(4, c2).Value = WkSel Then Set SourceCell = .Cells(5, c2) End If If .Cells(5, c2).Value = "" Then 'Set the source cell for filling up empty column .Cells(5, c2).Value2 = SourceCell.Value2 End If c2 = c2 + 1 Loop End With