title: Partial cell(or string) match in excel macro
body: <p>I am new to VBA and I would like to do a partial string (or cell) match between two sheets.</p>
  
  <p>An example of Name1 would be "IT executive Sally Lim"</p>
  
  <p>An example of Name2 would be "Sally Lim"</p>
  
  <pre><code>Name1 = Sheets("Work").Cells(RowName1, ColName1)
  Name2 = Sheets("Roster").Cells(RowName2, ColName2)
  
  'This condition doesn't work
  If Name1 = "*" &amp; Name2 &amp; "*" Then
      'The "Name2" comes out with a compile error: Invalid Qualifier
      Name2.Font.Strikethrough
      Exit Do
  Else
      End If
  </code></pre>
  
  <p>However, it is not working. When I run the coding, either nothing happens or an error pops out. Please help</p>
  
  <p>Edited coding:</p>
  
  <pre><code>If ShiftName Like "*" &amp; CashName &amp; "*" Then
      CashName.Font.Strikethrough = True
  </code></pre>
  
  <p>The strikeout portion has been solved and it does not shows the "Compile Error" anymore after I change my declaration from "string" to "range" as proposed by John Coleman.</p>
  
  <p>I tested by changing Name1 and Name2 to both Sally and then use the following condition for strikeout and it works. I believed that it is the "*" that has made the condition unworkable.</p>
  
  <pre><code>If ShiftName Like CashName Then
      CashName.Font.Strikethrough = True
  </code></pre>
  
  <p>How can a partial match be done by changing the condition accordingly?</p>
  
  <p>SECOND EDIT:</p>
  
  <p>MY BAD! I realised that my Name1 was in CAPTIALS.</p>