首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何进行条件复制,将一个工作表粘贴到另一个工作表中

如何进行条件复制,将一个工作表粘贴到另一个工作表中
EN

Stack Overflow用户
提问于 2013-12-27 10:50:24
回答 1查看 485关注 0票数 0

如果您能帮助我解决以下问题,我将不胜感激。我想从工作表1中进行条件复制,然后粘贴到工作表2中。例如,工作表1有两个单元格,这两个单元格数据必须粘贴在工作表2中的单个单元格中,也就是说,该单元格值较高,整个行数据必须粘贴到工作表2中。

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-12-27 13:34:18

对于您注释过的每一行,请尝试如下:

代码语言:javascript
复制
.Cells(LrowWsRR, 16).Value = Application.Max(wsI.Range("M8:M10").Value)

只需添加Excel的Max函数就可以为您完成工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20799329

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档