vba 如果满足条件,宏将值复制到另一个单元格中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27928143/
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:49:39  来源:igfitidea点击:

Macro to copy a value into another cell if a criteria is met

excelexcel-vbaexcel-formulavba

提问by 80gm2

I need to write a macro that for example, would copy the value from column A where the condition of cheese was met, and then pasted this value into the adjacent cell in the next column. Where would you start with this?

例如,我需要编写一个宏,从满足奶酪条件的 A 列复制值,然后将此值粘贴到下一列的相邻单元格中。你会从哪里开始呢?

enter image description here

在此处输入图片说明

回答by Gary's Student

Withouta macro:

没有宏:

In B2enter:

B2 中输入:

=IF(A2="CHEESE",A2,"")

and copy down

并复制下来

Witha macro:

使用宏:

Sub Cheesey()
    For Each r In Intersect(ActiveSheet.UsedRange, Range("A:A"))
        If r.Text = "CHEESE" Then
            r.Offset(0, 1) = "CHEESE"
        End If
    Next r
End Sub