title: VBA Selection.Find returns offset cell
body: <p>I am having problems with my code. I am trying to inset values into a &quot;database&quot; by using the find function to identify the correct rownumber. when i run the code the find function returns the next rownumber ie. the serchname is in row 300 but the data is inserted in row 301.</p>
  <p>the code i am using is as follows:</p>
  <pre><code>For Each Cell In Workbooks(controlfile).Sheets(&quot;Lab&quot;).Range(&quot;B9:B56&quot;)
      If Cell.Value &lt;&gt; &quot;&quot; Then
          
  'Range(&quot;N&quot; &amp; latestRow).Value = Right(DataArray(1), 4) &amp; Right(DataArray(2), 4)
  'Range(&quot;N&quot; &amp; latestRow).NumberFormat = &quot;00000000&quot;
          
          
          
          
          søgeOrd = Right(Cell.Value, 4) &amp; Right(Cell.Offset(0, 1), 4)
          Workbooks(controlfile).Sheets(&quot;Lab&quot;).Range(&quot;A1&quot;).Value = søgeOrd
          Workbooks(controlfile).Sheets(&quot;Lab&quot;).Range(&quot;A1&quot;).NumberFormat = &quot;00000000&quot;
          LinjeL = Cell.Row
          FGM = Workbooks(controlfile).Sheets(&quot;Lab&quot;).Range(&quot;F&quot; &amp; LinjeL).Value
          STA = Workbooks(controlfile).Sheets(&quot;Lab&quot;).Range(&quot;I&quot; &amp; LinjeL).Value
          BMK = Workbooks(controlfile).Sheets(&quot;Lab&quot;).Range(&quot;J&quot; &amp; LinjeL).Value
          VK = Workbooks(controlfile).Sheets(&quot;Lab&quot;).Range(&quot;L&quot; &amp; LinjeL).Value
          DP = Workbooks(controlfile).Sheets(&quot;Lab&quot;).Range(&quot;M&quot; &amp; LinjeL).Value
          SNB = Workbooks(controlfile).Sheets(&quot;Lab&quot;).Range(&quot;N&quot; &amp; LinjeL).Value
          Workbooks(controlfile).Sheets(&quot;Lab&quot;).Range(&quot;A1&quot;).ClearContents
          
          
          
          
          'find søgeord i database og indsæt de værdier som er fundet i lab
         
          Workbooks(FileName).Sheets(&quot;Database&quot;).Activate
          Columns(&quot;N:N&quot;).Select
          Set cellD = Selection.Find(What:=Workbooks(controlfile).Sheets(&quot;Lab&quot;).Range(&quot;A1&quot;).Value, After:=ActiveCell, LookIn:=xlFormulas, _
          LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
          MatchCase:=False, SearchFormat:=False)
          
          If Not cellD Is Nothing Then LinjeD = cellD.Row
                 
         
          If Range(&quot;E&quot; &amp; LinjeD).Value &lt;&gt; &quot;&quot; Then
          
          'kopier alle data til fejllog hvis der allerede er data
          Range(&quot;A&quot; &amp; LinjeD).Select
          ActiveCell.EntireRow.Copy
          Workbooks(FileName).Worksheets(&quot;Fejllog&quot;).Activate
          LastLine = Workbooks(FileName).Sheets(&quot;Fejllog&quot;).Range(&quot;A&quot; &amp; Rows.Count).End(xlUp).Offset(1, 0).Row
          Range(&quot;A&quot; &amp; LastLine).PasteSpecial
          
          Application.CutCopyMode = False
          
          
          Workbooks(FileName).Sheets(&quot;Database&quot;).Activate
          
          Range(&quot;E&quot; &amp; LinjeD).Value = FGM
          Range(&quot;H&quot; &amp; LinjeD).Value = STA
          Range(&quot;I&quot; &amp; LinjeD).Value = BMK
          Range(&quot;O&quot; &amp; LinjeD).Value = Format(Now, &quot;dd.mm.yyyy&quot;)
          Range(&quot;P&quot; &amp; LinjeD).Value = VK
          Range(&quot;Q&quot; &amp; LinjeD).Value = DP
          Range(&quot;R&quot; &amp; LinjeD).Value = SNB
          
          Workbooks(controlfile).Sheets(&quot;Lab&quot;).Activate
          
          Else
          
          Range(&quot;E&quot; &amp; LinjeD).Value = FGM
          Range(&quot;H&quot; &amp; LinjeD).Value = STA
          Range(&quot;I&quot; &amp; LinjeD).Value = BMK
          Range(&quot;O&quot; &amp; LinjeD).Value = Format(Now, &quot;dd.mm.yyyy&quot;)
          Range(&quot;P&quot; &amp; LinjeD).Value = VK
          Range(&quot;Q&quot; &amp; LinjeD).Value = DP
          Range(&quot;R&quot; &amp; LinjeD).Value = SNB
          
           Workbooks(controlfile).Sheets(&quot;Lab&quot;).Activate
  
          End If
          
      End If
  Next Cell
  </code></pre>
  <p>Any input would be greatly appreciated, thank you.</p>