title: Change from Public Function to Sub
body: <p>I have been using the below code to run a vlookup-style search and return all matches (whilst omitting duplicates and blanks). I want to convert this into a VBA macro that I can call using a button to, by row, search for the value in column C in column A, and return each corresponding value from column B. I want these results printed in column D, separated by a &quot;;&quot;. Does anyone know a good way to do this? I've also attached an example image of my goal output.</p>
  <p>Thanks!</p>
  <pre><code>Public Function Vlookup2(ByVal Lookup_Value As String, ByVal Cell_Range As 
  Range, ByVal Column_Index As Integer) As Variant
  Dim cell As Range
  Dim Result_String As String
  
  On Error GoTo eHandle
  
  For Each cell In Cell_Range
  
  If cell.Value = Lookup_Value Then
      If cell.Offset(0, Column_Index - 1).Value &lt;&gt; &quot;&quot; Then
          If Not Result_String Like &quot;*&quot; &amp; cell.Offset(0, Column_Index - 1).Value &amp; &quot;*&quot; Then
              Result_String = Result_String &amp; &quot;;!;&quot; &amp; cell.Offset(0, Column_Index - 1).Value
          End If
      End If
  End If
  
  Next cell
  
  Vlookup2 = LTrim(Right(Result_String, Len(Result_String) - 1))
  
  Exit Function
  
  eHandle:
  Vlookup2 = &quot;&quot;
  
  End Function
  </code></pre>
  <p><a href="https://i.stack.imgur.com/Gd9EA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Gd9EA.png" alt="enter image description here" /></a></p>