I have created a UserForm. I written code to update button. I am using a For Next loop to loop through the rows with if then statement. Example For i = 2 to 10, if the data is in row 2 or 3, it will update but if the data is in row 4 or high, it will not execute the if /then he statements. I have debug and it will only update the 1st line after the THEN statement. Any help would be appreciated.
VBA Code:
Sub Update()
Dim sh As Worksheet, iRow As Long, i As Integer
Set sh = ThisWorkbook.Sheets("Database")
iRow = sh.Range("A" & Rows.Count).End(xlUp).Row + 1
For i = 2 To iRow
If sh.Cells(i, 22).Value = frmForm.TxtLookup.Text Then
sh.Cells(i, 2) = frmForm.TxtTruck.Value
sh.Cells(i, 3) = frmForm.CmbVendor.Value
sh.Cells(i, 4) = frmForm.TxtPO.Value
sh.Cells(i, 5) = frmForm.TxtBOL.Value
sh.Cells(i, 6) = frmForm.CmbCarrier.Value
sh.Cells(i, 7) = frmForm.TxtPallet.Value
sh.Cells(i, 8) = IIf(frmForm.OptNo.Value = True, "No", "Yes")
sh.Cells(i, 9) = frmForm.TxtTemp.Value
sh.Cells(i, 10) = frmForm.TxtEmployee.Value
sh.Cells(i, 11) = frmForm.TxtGuardTime.Value
sh.Cells(i, 12) = frmForm.TxtDockTime.Value
sh.Cells(i, 13) = frmForm.TxtStartTime.Value
sh.Cells(i, 14) = frmForm.TxtEndTime.Value
sh.Cells(i, 15) = frmForm.TxtRcvStart.Value
sh.Cells(i, 16) = frmForm.TxtRcvComplete.Value
sh.Cells(i, 17) = frmForm.TxtReceiver.Value
sh.Cells(i, 18) = frmForm.CmbBio.Value
sh.Cells(i, 19) = frmForm.CmbCage.Value
sh.Cells(i, 20) = IIf(frmForm.CmbBio.Value = "All", frmForm.TxtPallet.Value, IIf(frmForm.CmbBio.Value = "", 0, frmForm.CmbBio.Value))
sh.Cells(i, 21) = IIf(frmForm.CmbCage.Value = "All", frmForm.TxtPallet.Value, IIf(frmForm.CmbCage.Value = "", 0, frmForm.CmbCage.Value))
End If
Next
End Sub
Call Reset
End Sub
Last edited by a moderator: