title: Copy/Paste Data Log Based on a Condition
body: <p>The following code copies a row of data from a Dashboard to a Data_Log as you repeatedly click the Start button. I am trying to add a condition that each time a <code>Yes</code> appears in column <code>D</code> of the Time Log copy the data from the Dashboard to the Data_Log and only click the Start button once to initiate as it should run continuously until you hit the Stop button.</p>
  <p>The problem is I cannot copy the data when the <code>Yes</code> condition appears on the Time_Log.</p>
  <p>Logic -&gt; Condition of <code>Yes</code> appears on the Time_Log -&gt; copy from Dashboard -&gt; paste to Data_Log -&gt; continues to copy/paste as the <code>Yes</code> increments on the Time_Log with time moving forward. Thank you for your help.</p>
  <p><img src="https://i.stack.imgur.com/KijHX.jpg" alt="enter image description here" /></p>
  <pre><code>Option Explicit
  
  Dim LoggingActive As Boolean
  Public Sub StartLoggingData()
      Application.StatusBar = &quot;Logging Dashboard Started&quot;
      LoggingActive = True
      CopyData
  End Sub
  Public Sub StopLoggingData()
      Application.StatusBar = &quot;Logging Dashboard Stopped&quot;
      LoggingActive = False
  End Sub
   
  Private Sub CopyData()
   
      Dim sht1 As Worksheet, sht2 As Worksheet, sht3 As Worksheet, cpyRng As Range, logRng As Long, rngLogTargetBeginningCell As Range, rngLastCellSelection As Range, r As Long, lastRow As Range
   
      If LoggingActive = True Then
  
          Set sht1 = ThisWorkbook.Sheets(&quot;Dashboard&quot;)
          Set sht2 = ThisWorkbook.Sheets(&quot;Data_Log&quot;)
          Set sht3 = ThisWorkbook.Sheets(&quot;Time_Log&quot;)
          Set cpyRng = sht1.Range(&quot;A39:Q39&quot;)
          Set rngLogTargetBeginningCell = sht2.Rows(sht2.Rows.Count).Columns(1).End(xlUp).Offset(1, 0)
          Set rngLastCellSelection = Selection ' remember the last selection because pasting will change the active cell
   
          Application.ScreenUpdating = False ' Stop Updating Graphic during data copy
          lastRow = sht3.Cells(Rows.Count).End(xlUp).Row
          For r = 4 To lastRow
              If sht3.Range(&quot;D&quot; &amp; r).Value = &quot;Yes&quot; Then
                  cpyRng.Copy
                  rngLogTargetBeginningCell.Offset(0, 1).PasteSpecial xlPasteValues
                  rngLastCellSelection.Select    ' reselect the old cell
              End If
          Next r
      End If
      Application.CutCopyMode = False ' Remove the copy area marker
      Application.ScreenUpdating = True  ' update graphics again
  End Sub
  </code></pre>