我正在尝试找到一种方法来复制第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我正在使用的数据的sample。
结果应如何显示应使用第5行中的最新值完全填充第5行
发布于 2016-11-11 22:38:18
根据我想我从你的解释中理解的,我猜这就是你想要的。
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 Withhttps://stackoverflow.com/questions/40549130
复制相似问题