如果您帮我解决以下问题,感谢您。我想从工作表1进行条件复制并粘贴到工作表2.例如,工作表1有两个单元格在两行中这两个单元格数据必须粘贴在工作表2中的单个单元格中,即整个行数据必须具有哪个单元格值高粘贴在表2中。
Sub UpdateData()
Dim wsI As Worksheet, WsRR As Worksheet, WsRRAT As Worksheet
Dim LrowWsRR As Long, LrowWsRRAT As Long
Dim i As Long, n As Long
n = 5
Set wsI = ThisWorkbook.Sheets("Input")
Set WsRR = ThisWorkbook.Sheets("Running RC202")
Set WsRRAT = ThisWorkbook.Sheets("Dossier Evaluation Template")
LrowWsRR = WsRR.Range("A" & WsRR.Rows.Count).End(xlUp).Row + 1
With WsRR
For i = 1 To 12
.Cells(LrowWsRR, i).Value = wsI.Range("E" & n).Value
n = n + 2
Next i
.Cells(LrowWsRR, 1).Value = wsI.Range("E6").Value
.Cells(LrowWsRR, 2).Value = wsI.Range("E8").Value
.Cells(LrowWsRR, 3).Value = wsI.Range("E10").Value
.Cells(LrowWsRR, 4).Value = wsI.Range("E12").Value
.Cells(LrowWsRR, 5).Value = wsI.Range("E14").Value
.Cells(LrowWsRR, 6).Value = wsI.Range("E16").Value
.Cells(LrowWsRR, 7).Value = wsI.Range("E18").Value
.Cells(LrowWsRR, 8).Value = wsI.Range("E20").Value
.Cells(LrowWsRR, 9).Value = wsI.Range("E22").Value
.Cells(LrowWsRR, 10).Value = wsI.Range("E24").Value
.Cells(LrowWsRR, 11).Value = wsI.Range("E26").Value
.Cells(LrowWsRR, 12).Value = wsI.Range("E28").Value
.Cells(LrowWsRR, 13).Value = wsI.Range("E30").Value
.Cells(LrowWsRR, 14).Value = wsI.Range("E32").Value
.Cells(LrowWsRR, 15).Value = wsI.Range("K8").Value
.Cells(LrowWsRR, 15).Value = wsI.Range("K10").Value
.Cells(LrowWsRR, 16).Value = wsI.Range("M8:M10").Value 'Here I want to do conditional copy paste
.Cells(LrowWsRR, 17).Value = wsI.Range("P8:P11").Value 'Here I want to do conditional copy paste
.Cells(LrowWsRR, 18).Value = wsI.Range("K12:K14").Value 'Here I want to do conditional copy paste
.Cells(LrowWsRR, 19).Value = wsI.Range("M12").Value
.Cells(LrowWsRR, 19).Value = wsI.Range("K14").Value
.Cells(LrowWsRR, 20).Value = wsI.Range("P12:P14").Value 'Here I want to do conditional copy paste
.Cells(LrowWsRR, 21).Value = wsI.Range("K16").Value
.Cells(LrowWsRR, 22).Value = wsI.Range("M16").Value
.Cells(LrowWsRR, 23).Value = wsI.Range("P16").Value
.Cells(LrowWsRR, 24).Value = wsI.Range("K18").Value
.Cells(LrowWsRR, 25).Value = wsI.Range("M18").Value
.Cells(LrowWsRR, 26).Value = wsI.Range("P18").Value
.Cells(LrowWsRR, 27).Value = wsI.Range("K20:K26").Value 'Here I want to do conditional copy paste
.Cells(LrowWsRR, 28).Value = wsI.Range("M20:M26").Value 'Here I want to do conditional copy paste
.Cells(LrowWsRR, 29).Value = wsI.Range("P20:P26").Value 'Here I want to do conditional copy paste
.Cells(LrowWsRR, 30).Value = wsI.Range("M30").Value
.Cells(LrowWsRR, 31).Value = wsI.Range("M32").Value
.Cells(LrowWsRR, 32).Value = wsI.Range("M34").Value
End With
End Sub
答案 0 :(得分:0)
对于您评论过的每一行,请尝试以下操作:
.Cells(LrowWsRR, 16).Value = Application.Max(wsI.Range("M8:M10").Value)
只需添加Excel的Max功能即可为您完成工作。