/ / Excel userform: comment vérifier certaines cellules avant d'accepter des données? - excel, vba, userform

Userform Excel: comment vérifier certaines cellules avant d'accepter des données? - excel, vba, userform

Private Sub CancelCommandButton_Click()
Unload Me
End Sub

Private Sub ClearCommandButton_Click()
Call UserForm_Initialize
End Sub

Private Sub OkCommandButton_Click()
Dim emptyRow As Long

Sheet1.Activate

emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1

Cells(emptyRow, 1).Value = EntityNameTextBox.Value
Cells(emptyRow, 2).Value = JurComboBox.Value
Cells(emptyRow, 3).Value = MailTypeComboBox.Value
End Sub

Private Sub UserForm_Initialize()
EntityNameTextBox.Value = ""

JurComboBox.Clear

With JurComboBox
.AddItem "AL"
.AddItem "AK"
.AddItem "AR"
.AddItem "AZ"
.AddItem "CA"
.AddItem "CO"
.AddItem "CT"
.AddItem "DE"
.AddItem "HI"
.AddItem "IA"
End With

MailTypeComboBox.Clear

With MailTypeComboBox
.AddItem "AR"
.AddItem "ARR"
.AddItem "DOR"
.AddItem "DTN"
.AddItem "FAR"
End With

EntityNameTextBox.SetFocus
End Sub

Réponses:

0 pour la réponse № 1

Veuillez utiliser ce code:

Private Sub OkCommandButton_Click()
Dim emptyRow As Long
Dim MsgString as String

Sheet1.Activate

emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1

MsgString = "Do you want to update data?" & vbNewLine & "A" & emptyRow & " = " & EntityNameTextBox.Value & vbNewLine & "B" & emptyRow & " = " & JurComboBox.Value & vbNewLine & "C" & emptyRow & " = " & MailTypeComboBox.Value
If MsgBox(MsgString, vbYesNo, "Update confirmation...!!!") = vbYes Then
Cells(emptyRow, 1).Value = EntityNameTextBox.Value
Cells(emptyRow, 2).Value = JurComboBox.Value
Cells(emptyRow, 3).Value = MailTypeComboBox.Value
Else
Msgbox "Data Update failed.", vbExclamation, "Failed update data."
End If
End Sub

J'espère que cette aide