[英]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.