Comparing unique strings in two columns and updating third column

Snuffle

New Member
Joined
Oct 28, 2016
Messages
2
Hello

I am trying to find a string in Column D and Column H and if they match certain criteria, insert the string "Match" in Column W.

For example, if the string "Auditorium" occurs in Column D and the string "INTERNAL" occurs in Column H on the same row, insert the string "Match" in Column W.

My code below inserts the string "Match" in Column W against all rows that contain the string "INTERNAL" irrespective of the string in Column D!

Any advice would be appreciated!

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Row No[/TD]
[TD]Column D[/TD]
[TD]Column H[/TD]
[TD]Column W[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Auditorium[/TD]
[TD]Martin (INTERNAL)[/TD]
[TD]None commercial rate[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Auditorium[/TD]
[TD]John[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Theatre[/TD]
[TD]Edward (INTERNAL)[/TD]
[TD]None commercial rate[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Theatre[/TD]
[TD]George[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Code:
Dim celA
Dim celB
For Each celA In Range("D1:D50")[INDENT]For Each celB In Range("H1:H50")[/INDENT]
[INDENT]         If InStr(1, celA.Value, "Auditorium") <> 0 And InStr(1, celB.Value, "INTERNAL") <> 0 Then celB.Offset(0, 10).Value = "None commercial rate"[/INDENT]
[INDENT]Next celB[/INDENT]
Next celA
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
try this:

Code:
Sub Snuffle()
For Each cl In Range("D1:D50")
If InStr(cl, "Auditorium") > 0 And InStr(cl.Offset(, 4), "INTERNAL") <> 0 Then cl.Offset(, 19) = "Match"
Next
End Sub
 
Last edited:
Upvote 0
If you want the comparisons to be case insensitive
Code:
Sub Check()
   Dim Cl As Range
   For Each Cl In Range("D1", Range("D" & Rows.Count).End(xlUp))
      If InStr(1, Cl, "auditorium", vbTextCompare) > 0 And InStr(1, Cl.Offset(, 4), "internal", vbTextCompare) > 0 Then Cl.Offset(, 19) = "Match"
   Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top