title: Highlight surrounding cells of selected cell
body: <p>I am trying to exercise Levenshtein Distance in Excel. To fill the cells, we need to consider the minimum of three cells (left, up-left, and up). It is easy to find minimum of those three if they were highlighted.</p>
  <p>I want to highlight those three cells whenever I put my cursor on any empty cell. Just like shown on image below. When I put my cursor on C3; B2, B3, and C2 should be higlighted.</p>
  <img src="https://i.stack.imgur.com/SnLn9.png" width="600" />
  <p>I found a VBA script. But it higlightes the entire row and column of cursor cell. I am not familiar with VBA, therefore can't modify rows and columns to my way.</p>
  <pre><code>Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
  'Update 20200430
  Static xRow
  Static xColumn
  If xColumn &lt;&gt; &quot;&quot; Then
      With Columns(xColumn).Interior
          .ColorIndex = xlNone
      End With
      With Rows(xRow).Interior
          .ColorIndex = xlNone
      End With
  End If
  pRow = Selection.Row
  pColumn = Selection.Column
  xRow = pRow
  xColumn = pColumn
  With Columns(pColumn).Interior
      .ColorIndex = 6
      .Pattern = xlSolid
  End With
  With Rows(pRow).Interior
      .ColorIndex = 6
      .Pattern = xlSolid
  End With
  End Sub
  </code></pre>
  <p>this is what it does</p>
  <p><a href="https://i.stack.imgur.com/pmWaE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pmWaE.png" alt="Output of code that Found" /></a></p>