在Sheet1中查找单元格中的值并将其粘贴到Sheet2

时间:2013-09-05 22:40:34

标签: excel vba excel-vba

我希望VBA在Sheet1中找到名为“Apple”的单元格标题(在行a1中),并将该数据粘贴到名为“Sheet2中的橙色”的单元格标题中

Sheet1     Sheet2

Apple      Orange
1
2
3
4

我正在尝试不包含单元格标题,因此它只会抓取数字。

下面的内容会起作用吗?

Sheet1.Rows("1:1").Find(What:="Apple", After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate
Selection.EntireColumn row-1.Copy sheet2.range("a2")

entirecolumn row -1这样的东西,以便它不会复制标题单元格...
不知道我在做什么,但帮助会很棒!

1 个答案:

答案 0 :(得分:0)

未测试:

Dim rng as range, rngCopy as range, rng2 as range

set rng = Sheet1.Rows(1).Find(What:="Apple", LookIn:=xlValues, LookAt:=xlWhole)

if not rng is nothing then

    set rngCopy = Sheet1.range(rng.offset(1,0), _
                               Sheet1.cells(rows.count,rng.column).end(xlUp))

    set rng2 = Sheet2.Rows(1).Find(What:="Orange", LookIn:=xlValues, _
                                   LookAt:=xlWhole)

    if not rng2 is nothing then rngCopy.copy rng2.offset(1,0)

end if