下面的代码用于将 sheet1 中“Apple”列下的值复制到 sheet2 中的“AppleNew”列。(感谢蒂姆)
但是如果我有多个列(橙色、香蕉等),有没有办法编写更简单的代码,通过循环而不是复制和粘贴每一列的代码?
Dim rng as range, rngCopy as range, rng2 as range
set rng = Sheet1.Rows(3).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:="AppleNew", LookIn:=xlValues, _
LookAt:=xlWhole)
if not rng2 is nothing then rngCopy.copy rng2.offset(1,0)
end if