[英]Copy and Paste Selected Cell onto entire row until Column above is empty
我试图找到一种方法来复制第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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.