You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Excel VBA循环列引用问题:跨工作表复制同位置单元格

Hey Brian, I see the issue with that line—you can't directly reference the cell using the variable c like Worksheets("CSV").c because VBA doesn't recognize that syntax. Instead, we need to target the exact same row and column as c in the "CSV" worksheet.

Here's the corrected line for setting a:

Set a = Worksheets("CSV").Cells(c.Row, c.Column)

This works because c.Row pulls the row number of the current cell in CSV2, and c.Column grabs its column number. Using Cells(row, column) on the "CSV" worksheet lets us pinpoint the exact same position cell you need.

Your full corrected code would look like this (I also fixed a small logical operator issue in your If statement—you used & for concatenation instead of And for logical checks, which would have caused unexpected behavior):

Sub et()
 Dim c As Range
 Dim a As Range
 Worksheets("CSV2").Select
 '//loop it
 For Each c In Range(Range("E2"), Range("E2").End(xlDown))
 Set a = Worksheets("CSV").Cells(c.Row, c.Column) '// Fixed this line!
 If c.Value > 0 And c.Value < 3 Then '// Fixed logical operator here
 Sheets("CSV").Select
 a.Copy'// 此处我要复制CSV工作表的内容
 Sheets("CSV2").Select
 c.PasteSpecial Paste:=xlPasteValues'// 此处我要粘贴到CSV2工作表
 End If
 Next
 Worksheets("RETURN").Select
End Sub

内容的提问来源于stack exchange,提问作者Brian D

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 07:54:55