Te anexo la última versión del código. Es del formulario UFMOC
Private Sub btnmocAC_Click()
Dim strfila$
Worksheets("Proveedor").Activate
Dim fila As String
[A65536].End(xlUp).Offset(1, 0).Select
If Modificar = True Then
Range("A" & FilaModificacion).Activate
strfila$ = FilaModificacion
Else
strfila$ = ActiveCell.Row
ActiveCell = Val(lblregcli)
End If
Range("A" + strfila$) = txtmoc1
Range("B" + strfila$) = txtmoc2
Range("C" + strfila$) = txtmoc3
Range("D" + strfila$) = txtmoc4
Range("E" + strfila$) = txtmoc5
Range("F" + strfila$) = txtmoc6
Range("G" + strfila$) = txtmoc7
Range("H" + strfila$) = txtmoc8
Range("A1").End(xlDown).Select
NumReg = ActiveCell.Value + 1
txtmoc1 = "": txtmoc2 = "": txtmoc3 = "": txtmoc4 = "": txtmoc5 = "": txtmoc6 = "": txtmoc7 = "": txtmoc8 = "":
If Modificar = True Then
Modificar = False
Unload Me
UFBC.Show
End If
Exit Sub
txtmoc4.SetFocus
End Sub
'Solo numeros, guion y cantidad caracteres. Puede separarse uno del otro
Private Sub txtmoc6_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If Not (KeyAscii >= 48 And KeyAscii <= 57) Then
KeyAscii = 0 '<-- El KeyAscii = 0 es para borrar la tecla presionada equivocadamente
MsgBox "Ingrese SOLO numeros, en el campo, el guion entra automatico", vbOKOnly + vbInformation, Title:="CARACTER NULO"
End If
If Len(txtmoc6) = 12 Then KeyAscii = 0
If Len(txtmoc6) = 12 Then MsgBox "LLego al maximo posible de caracteres": Exit Sub
'Para Guion
Select Case Len(txtmoc6)
Case 4
txtmoc6.Text = txtmoc6.Text & "-"
End Select
End Sub
Private Sub txtmoc7_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If Not (KeyAscii >= 48 And KeyAscii <= 57) Then
KeyAscii = 0
MsgBox "Ingrese SOLO numeros, en el campo, el guion entra automatico", vbOKOnly + vbInformation, Title:="CARACTER NULO"
End If
If Len(txtmoc7) = 12 Then KeyAscii = 0
If Len(txtmoc7) = 12 Then MsgBox "LLego al maximo posible de caracteres": Exit Sub
'Para Guion
Select Case Len(txtmoc7)
Case 4
txtmoc7.Text = txtmoc7.Text & "-"
End Select
End Sub
Private Sub UserForm_Initialize()
Worksheets("Proveedor").Activate
Range("A2").Select
If Modificar = False Then
If ActiveCell = Empty Then
lblregcli = 1000
Else
Range("A1").End(xlDown).Select
lblregcli = ActiveCell.Value + 1
End If
Else
lblregcli = Range("A" & FilaModificacion)
txtmoc1 = Range("A" & FilaModificacion)
txtmoc2 = Range("B" & FilaModificacion)
txtmoc3 = Range("C" & FilaModificacion)
txtmoc4 = Range("D" & FilaModificacion)
txtmoc5 = Range("E" & FilaModificacion)
txtmoc6 = Range("F" & FilaModificacion)
txtmoc7 = Range("G" & FilaModificacion)
txtmoc8 = Range("H" & FilaModificacion)
txtmoc4.SetFocus
End If
End Sub
Private Sub btnmocVL_Click()
Modificar = False
Unload Me
UFBC.Show
End Sub
Private Sub Userform_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "Por favor, para salir usa el boton correspondiente", vbInformation, "LEA"
End If
End Sub
Private Sub btnmocBO_Click()
txtmoc4 = "": txtmoc5 = "": txtmoc6 = "": txtmoc7 = "": txtmoc8 = "":
Modificar = False '<==
txtmoc4.SetFocus
End Sub