[英]Add text to a cell in column X if match in column Y
I'm trying to do the following thing: 我正在尝试执行以下操作:
My file has 2 columns. 我的文件有2列。
In "A" is a full list of products ordered by clients. “ A”中是客户订购的产品的完整列表。
In "C" is a list of products which need to have a specific text added in "A" column, in case they've been ordered (it's unfortunately not possible to do it in the database). “ C”中的产品列表,需要订购的产品需要在“ A”列中添加特定的文本(不幸的是,无法在数据库中完成此操作)。
I don't know how to end the macro: 我不知道如何结束宏:
Sub SEARCH2()
Dim CompareRange As Variant, x As Variant, y As Variant
Set CompareRange = Range("A1:A500")
Set CompareRange2 = Range("C3:C500")
For Each x In CompareRange2
For Each y In CompareRange
If x = y Then x ?????
'THERE I WANT TO SAY ADD THE TEXT "EXAMPLE" TO THE CELL
Next y
Next x
End Sub
Could someone help to end this macro? 有人可以帮助结束此宏吗?
very best regards. 美好祝愿。
You must declare variable x, y as range 您必须将变量x,y声明为范围
Dim CompareRange As Variant, x As Range, y As Range
If x = y Then x = "EXAMPLE"
This is a best guess, but it's not clear what you are asking. 这是一个最佳猜测,但不清楚您要问什么。 You don't need to loop through both ranges. 您无需遍历两个范围。
Sub SEARCH2()
Dim CompareRange As Range, CompareRange2 As Range, x As Range, y As Range, v As Variant
Set CompareRange = Range("A1:A500")
Set CompareRange2 = Range("C3:C500")
For Each x In CompareRange2
v = Application.Match(x, CompareRange, 0)
If IsNumeric(v) Then
x.Value = x.Value & " EXAMPLE"
End If
Next x
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.