Comment afficher une boîte de message différente lorsqu'elle rencontre l'état

Je souhaite afficher une boîte de message différente lorsqu'elle répond à l'exigence suivante:

  1. Lorsque la valeur de la textbox8 est inférieure à 3, la boîte de message affichera que textbox8 est hors de scope, l'user souhaite continuer à stocker datatables, si l'user a frappé oui, il continuera à stocker datatables mais si l'user sélectionne non, il vous requestra de rentrer textbox8 value puis ne stockez que datatables.

  2. Lorsque la valeur textbox8 est comprise entre 3 et 3,2, la boîte de message affichera textbox8 entre 3 et 3,2, soyez conscient et affichez un button OK pour que l'user puisse cliquer et save datatables.

J'ai essayé d'append une autre boîte de message à l'intérieur, mais elle ne vérifiera que la première condition.

Sheets("Overall").Activate With Me If Len(.ComboBox5.Value) * Len(.TextBox4.Value) * Len(.TextBox5.Value) * Len(.TextBox6.Value) * Len(.ComboBox6.Value) * Len(.TextBox7.Value) * Len(.TextBox8.Value) = 0 Then MsgBox "Please Complete All Fields Before Submit" Else If CSng(.TextBox8.Text) < 3 Then If MsgBox("TextBox8 less than 3.0" & vbLf & vbLf & _ "Do you wish to continue?", vbYesNo, "Exceeds") = vbNo Then MsgBox "user to re-type the value in TextBox8.", vbInformation, "Title" TextBox8.SetFocus Else If CSng(.TextBox8.Text) >= 3 And CSng(.TextBox8.Text) <= 3.2 Then MsgBox "TextBox8 between 3 to 3.2, Aware!!!", , "Alert" Exit Sub End If End If End If eRow = Sheet4.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row Cells(eRow, 11).Value = ComboBox5.Text Cells(eRow, 7).Value = TextBox4.Text Cells(eRow, 8).Value = TextBox5.Text Cells(eRow, 14).Value = TextBox6.Text Cells(eRow, 16).Value = ComboBox6.Text Cells(eRow, 12).Value = TextBox7.Text Cells(eRow, 13).Value = TextBox8.Text Cells(eRow, 19).Value = TextBox9.Text End If End With End Sub 

Cette ligne de code If CSng(.TextBox8.Text) >= 3 And CSng(.TextBox8.Text) <= 3.2 Then il ne doit pas être dans le If CSng(.TextBox8.Text) < 3 Then , le bloc de code. Si vous modifiez le code et réparez votre empreinte, le code ressemble à:

  Sheets("Overall").Activate With Me If Len(.ComboBox5.Value) * Len(.TextBox4.Value) * Len(.TextBox5.Value) * Len(.TextBox6.Value) * Len(.ComboBox6.Value) * Len(.TextBox7.Value) * Len(.TextBox8.Value) = 0 Then MsgBox "Please Complete All Fields Before Submit" Else ' If Len(.ComboBox5.Value) * Len(.TextBox4.Value) If CSng(.TextBox8.Text) < 3 Then If MsgBox("TextBox8 less than 3.0" & vbLf & vbLf & _ "Do you wish to continue?", vbYesNo, "Exceeds") = vbNo Then MsgBox "user to re-type the value in TextBox8.", vbInformation, "Title" TextBox8.SetFocus End If ' If MsgBox("TextBox8 less than 3.0" End If ' If CSng(.TextBox8.Text) < 3 Then If CSng(.TextBox8.Text) >= 3 And CSng(.TextBox8.Text) <= 3.2 Then MsgBox "TextBox8 between 3 to 3.2, Aware!!!", , "Alert" Exit Sub End If ' If CSng(.TextBox8.Text) >= 3 And eRow = Sheet4.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row Cells(eRow, 11).Value = ComboBox5.Text Cells(eRow, 7).Value = TextBox4.Text Cells(eRow, 8).Value = TextBox5.Text Cells(eRow, 14).Value = TextBox6.Text Cells(eRow, 16).Value = ComboBox6.Text Cells(eRow, 12).Value = TextBox7.Text Cells(eRow, 13).Value = TextBox8.Text Cells(eRow, 19).Value = TextBox9.Text End If ' If Len(.ComboBox5.Value) * Len(.TextBox4.Value) End With End Sub 

Si vous trouvez que vous avez beaucoup de blocs If dans votre code, vous pouvez également append des commentaires aux lignes Else et End If pour montrer à quelle déclaration If appartiennent. Je l'ai fait dans le code ci-dessus.