Agregar mensaje de error "Ya existe un valor" en una macro?
Tengo esta macro la cual me ayudaron a crearla aquí, lo que me gustaría agregarle es que cada que ya exista un valor en la celda NO me permita colocar uno, sino que me arroje el mensaje "Ya existe un valor en la celda"
Sub Pegar()
Set h = ActiveSheet
'validaciones
If h.ComboBox1.Value = "" Then
MsgBox "Falta el artículo", vbExclamation
Exit Sub
End If
If h.ComboBox2.Value = "" Then
MsgBox "Falta la talla", vbExclamation
Exit Sub
End If
If h.ComboBox3.Value = "" Then
MsgBox "Falta el color", vbExclamation
Exit Sub
End If
fecha = h.Range("B2").Value
If fecha = "" Or Not IsDate(fecha) Then
MsgBox "Falta la fecha", vbExclamation
Exit Sub
End If
Set b = h.Rows(4).Find(fecha, lookat:=xlWhole)
If Not b Is Nothing Then
col = b.Column
Else
MsgBox "No existe la fecha", vbCritical
Exit Sub
End If
Set b = Nothing
'
valor = h.Range("C2").Value
If valor = "" Or Not IsNumeric(valor) Then
MsgBox "Falta el valor de producción"
Exit Sub
End If
'
'Busca
existe_art = False
Set r = h.Columns("A")
Set b = r.Find(h.ComboBox1.Value, lookat:=xlWhole)
If Not b Is Nothing Then
celda = b.Address
Do
'detalle
If LCase(h.Cells(b.Row, "B").Value) = LCase(h.ComboBox2.Value) And _
LCase(h.Cells(b.Row, "C").Value) = LCase(h.ComboBox3.Value) Then
existe_art = True
fila = b.Row
h.Cells(fila, col) = valor
MsgBox "Valor actualizado", vbInformation
Exit Do
End If
Set b = r.FindNext(b)
Loop While Not b Is Nothing And b.Address <> celda
End If
If existe_art = False Then
MsgBox "No existe el artículo", vbCritical
End If
End Sub
1 Respuesta
Respuesta de Aneudys Martinez