title: Run existing Macro only on Selected Cells, instead of the whole sheet
body: <p>I have the following macro (LibreOffice Calc):</p>
  
  <pre><code>Sub CalcFindAndReplace
      Dim oDoc,aFind,aReplace,aRayCount,FandR,oSheet
      oDoc = ThisComponent
      aFind = Array("Mecanica","Cancion","Murcielago")
      aReplace = Array("Mecánica","Canción","Murciélago")
      aRayCount = 0
      oSheet = oDoc.getSheets.getByName(oDoc.CurrentSelection.Spreadsheet.Name)
      FandR = oSheet.createReplaceDescriptor
      FandR.SearchCaseSensitive = true
      FandR.SearchWords = true ' 1 to A but not 11 to AA
      FandR.SearchRegularExpression = true
  
      While aRayCount &lt;= uBound(aFind)
          FandR.setSearchString(aFind(aRayCount))
          FandR.setReplaceString(aReplace(aRayCount))
          aRayCount = aRayCount + 1
          oSheet.ReplaceAll(FandR)
      End While
  
  End Sub
  </code></pre>
  
  <p>It works fine, but I need to add it the ability to be applied only on manual selections of cells (different each time), not on all the cells of the sheet.</p>