vba 如何使用vba复制excel单元格值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26710182/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 05:06:28 来源:igfitidea点击:
How to copy excell cell value using vba
提问by user3305327
I am trying to copy cell values from one excel sheet to another. For this I have written the following code:
我正在尝试将单元格值从一个 Excel 工作表复制到另一个。为此,我编写了以下代码:
Dim p As Variant
For p = 2 To 12000
If ThisWorkbook.Sheets("Sheet1").Cells(p, 1).Value = ThisWorkbook.Sheets("Sheet2").Cells(p, 7).Value Then
Sheet1.Cells(p, 9).Value = Sheet2.Cells(p, 7).Value
End If
Next p
The comparison is done only the copying is not completing...can you please help me with this.
比较只完成了复制没有完成......你能帮我解决这个问题吗?
Thanks in advance
提前致谢
采纳答案by Matteo NNZ
This is working for me:
这对我有用:
Dim p As Long
For p = 2 To 12000
If ThisWorkbook.Sheets("Sheet1").Cells(p,1).Value = ThisWorkbook.Sheets("Sheet2").Cells(p,7).Value Then
ThisWorkbook.Sheets("Sheet1").Cells(p,9).Value = ThisWorkbook.Sheets("Sheet2").Cells(p,7).Value
End If
Next p
回答by sudipto
Why not use this:
为什么不使用这个:
ThisWorkbook.Sheets("Sheet1").Cells(p, 9).Value = ThisWorkbook.Sheets("Sheet2").Cells(p, 7).Value