title: Enter Condition Value using Excel User Form
body: <p>I am trying to code a user form to add entered values in the row associated with a specified value. I want a form to appear with two text boxes "Task Name" and "Task Quantity". </p>
  
  <p>I then want excel to search a column that is specified with an input box "Task Column" (usually a or B) then paste the value from the user form "Task Quantity" in the column specified with another input box "Unit Column"</p>
  
  <p><a href="https://i.stack.imgur.com/S3Ce0.png" rel="nofollow noreferrer">User Form Image</a></p>
  
  <p>Here is my code so far: </p>
  
  <pre><code>Public Sub UserForm_Initialize()
      Dim tskCol As String
          tskCol = Application.InputBox("Enter Column Letter for Task Names", , , , , , , 2)
      Dim unitCol As String
          unitCol = Application.InputBox("Enter Column for Number of Units", , , , , , , 2)
  End Sub
  
  Private Sub cmdAdd_Click()
      Dim LastRow As Long
      Dim i As Long
      LastRow = Range("tskCol" &amp; Rows.Count).End(xlUp).Row
          'Copy input values to sheet.
      For i = 2 To LastRow
          If Range("tskCol" &amp; i).Value = Me.txtTask Then
              Range("unitCol" &amp; i).Replace What:="", Replacement:=Me.txtQuantity, LookAt:=xlPart _
              , SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
              ReplaceFormat:=False
          End If
      Next i
  
      'Clear input controls.
      Me.txtTask.Value = ""
      Me.txtQuantity.Value = ""
  
  
  End Sub
  </code></pre>
  
  <p><strong>Edited code</strong></p>
  
  <pre><code>    Option Explicit
  Public tskCol As String
  Public unitCol As String
  Sub UserForm_Initialize()
      tskCol = Application.InputBox("Enter Column Letter for Task Names", , , , , , , 2)
      unitCol = Application.InputBox("Enter Column for Number of Units", , , , , , , 2)
  End Sub
  
  Private Sub cmdAdd_Click()
      Dim LastRow As Long
      Dim i As Long
      LastRow = ActiveSheet.Range(tskCol &amp; Rows.Count).End(xlUp).Row
          'Copy input values to sheet.
      For i = 2 To LastRow
          If ActiveSheet.Range(tskCol &amp; i).Value = Me.txtTask Then
              ActiveSheet.Range(unitCol &amp; i).Value = Me.txtQuantity.Value
          End If
      Next i
  
      'Clear input controls.
      Me.txtTask.Value = ""
      Me.txtQuantity.Value = ""
  
  
  End Sub
  </code></pre>