-1

我希望 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这样它不会复制标题单元格......
不知道我在做什么,但帮助会很棒!

4

1 回答 1

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
于 2013-09-06T00:40:24.280 回答