Search code examples
excelvbaloopscopyuserform

how to find id in column D, when found paste date from column g into textbox17


Using userform1 to search column d for an ID, when found get ID date from column g and paste date in textbox17.... something like this but this code isn't working.

 Private Sub CommandButton4_Click()
Dim id As String
Dim finalrow As Integer
Dim i As Integer

id = TextBox16.Value
finalrow = Sheets("ALL P.O. INFO").Range("D1000").End(xlUp).ROW

For i = 2 To finalrow
    If Cells(i, 4) = id Then
       Range(Cells(i, 7)).Copy
      TextBox17.Paste
    End If
Next i

End Sub

Solution

  •   {Private Sub CommandButton4_Click()
    Dim id As String
    Dim finalrow As Integer
    Dim i As Integer
    
    id = TextBox16.Value
    finalrow = Sheets("ALL P.O. INFO").Range("D1000").End(xlUp).ROW
    
    For i = 2 To finalrow
        If Cells(i, 4) = id Then
          Me.TextBox17 = Cells(i, 7).Value
        End If
    Next i
    
    End Sub}