lundi 27 juillet 2020

Next without for error userform Excel VBA error with Else-If Statement

I am getting a "Next without For" error which I don't understand why.

I have a userform with 2 textboxes and 1 ComboBox
[![UserformPictureLabeled][1]][1]

When I click Submit button, IF the serial number matches existing data in column 4, I want the data to fill in the Disposition column (3 rows to the right) with text from ComboBox1...

If it DOES NOT match I want to fill a brand new row...

If no disposition is inputted, I want to exit the sub or message box.. either is ok.

I tried re-arranging IF,ELSE,FOR, NEXT... but nothing seems to work.

      Private Sub SubmitButton_Click()

      Dim serial_ID As String
      serial_ID = Trim(SN_TextBox1.Text)
      DispValue = ComboBox1.Value

      Worksheets("RMA Tracker").Activate
      lastrow = ActiveSheet.Cells(Rows.Count, 4).End(xlUp).Row

      For i = 2 To lastrow
     

       'Searches for matching RMA & SN 'this assigns data to Log Sheet, if the data is brand new

            If Worksheets("Sheet1").Cells(i, 4).Value <> serial_ID Then
               ActiveSheet.Cells(i + 1, 1) = RMA_TextBox1.Value
               ActiveSheet.Cells(i + 1, 4) = SN_TextBox1.Value
               ActiveSheet.Cells(i + 1, 7) = ComboBox1.Value


            Else
        
       'this assigns data to disposition column to matching entries in serial number column

             If Worksheets("Sheet1").Cells(i, 4).Value = serial_ID Then
             ComboBox1.Text = Worksheets("Sheet1").Cells(i, 7).Value
 
 
             Else
       
       
             If DispValue = "" Then
             Exit Sub
      

             End If

     Next i

     'this clears the fields of userform when button is clicked and saves it automatically
     ActiveWorkbook.Save
     Call resetform


      End Sub`


  [1]: https://i.stack.imgur.com/y7CyG.png

Aucun commentaire:

Enregistrer un commentaire