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!

Row NoColumn DColumn HColumn W
1AuditoriumMartin (INTERNAL)None commercial rate
2AuditoriumJohn
3TheatreEdward (INTERNAL)None commercial rate
4TheatreGeorge

<tbody>
</tbody>

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

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
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,215,461
Messages
6,124,955
Members
449,200
Latest member
indiansth

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