vba 如果条件满足,如何复制单元格并粘贴到另一个单元格中?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28204866/
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
How to copy cell if condition is met and paste in another cell?
提问by lon0316
I'm completely stuck and needs someone to offer up some fresh code because I'm not even close to figuring this out. There are two things I need to do.
我完全被困住了,需要有人提供一些新代码,因为我什至还没有弄清楚这一点。我需要做两件事。
- If M2>0 then copy M2 and paste it into D2. Continue doing this until every cell in "M" has been evaluated based on row count.
- Next, if I end up copying and pasting based on meeting condition then I want to also change Item Status in column F to say "FALSE". Hope someone can help I'm at the tail end of a large project being completed.
- 如果 M2>0,则复制 M2 并将其粘贴到 D2 中。继续这样做,直到根据行数评估了“M”中的每个单元格。
- 接下来,如果我最终根据满足条件进行复制和粘贴,那么我还想将 F 列中的项目状态更改为“FALSE”。希望有人可以帮助我正在完成一个大型项目的尾声。
回答by Lance Roberts
For #1, In D2 put
对于 #1,在 D2 中放入
=IF(M2>0,M2,"")
Then click and drag down the entire column
然后单击并向下拖动整个列
Then in F2 put
然后在F2放
=IF(M2>0,"FALSE","TRUE")
Then click and drag down the entire column (assuming "TRUE" is what else is suppose to be in there.
然后单击并向下拖动整个列(假设“TRUE”是其中的其他内容。
In VBA, here's one way:
在 VBA 中,这是一种方法:
For i = 2 to ActiveSheet.UsedRange.Rows.Count
If Range("M"&i).Value > 0 Then
Range("D"&i).Value = Range("M"&i).Value
Range("F"&i).Value = "FALSE"
Next i

