Tengo un formulario de entrada de datos, para lo cual he creado un
UserForm con varios TextBox y Combobox, y tres CommandButton,
(CommandButton1 para Registrar; el CommandButton2 para Cancelar y el
CommandButton3 para Salir del Formulario). El problema me surge con
uno de los CommandButton, concretamente el CommandButton2 que lo
utilizo para Cancelar. Siempre que lo acciono me da el siguiente
error:
"Error de compilación:
No se encontró el método o el dato miembro"
Le doy aceptar y, en la macro, se marca en amarillo lo siguiente:
"Private Sub CommandButton2_Click()"
La macro con la que estoy funcionando, es la siguiente:
Private Sub CommandButton1_Click()
If TextBox1.Value = "" Or TextBox1.Value = "" Or TextBox2.Value = ""
Or ComboBox3.Value = "" Or TextBox3.Value = "" Or ComboBox5.Value = ""
Or ComboBox6.Value = "" Or ComboBox7.Value = "" Or ComboBox8.Value "" Or ComboBox9.Value = "" Or ComboBox10.Value = "" Or
ComboBox11.Value = "" Or ComboBox12.Value = "" Then
MsgBox ("FALTAN CASILLAS POR LLENAR")
Exit Sub
End If
Sheets("ESTADISTICA").Visible = True
Sheets("estadistica").Select
contar = Application.WorksheetFunction.CountA(Range("a2:a50000"))
Cells(contar + 2, 1) = contar + 1
Range("registro") = contar + 1
Cells(contar + 2, 2) = TextBox1.Value
Cells(contar + 2, 3) = TextBox2.Value
Cells(contar + 2, 4) = ComboBox3.Value
Cells(contar + 2, 5) = TextBox3.Value
Cells(contar + 2, 6) = ComboBox5.Value
Cells(contar + 2, 7) = ComboBox6.Value
Cells(contar + 2, 8) = ComboBox7.Value
Cells(contar + 2, 9) = ComboBox8.Value
Cells(contar + 2, 10) = ComboBox9.Value
Cells(contar + 2, 11) = ComboBox10.Value
Cells(contar + 2, 12) = ComboBox11.Value
Cells(contar + 2, 13) = ComboBox12.Value
Sheets("ESTADISTICA").Visible = False
Sheets("inicio").Select
End Sub
Private Sub CommandButton2_Click() AQUÍ ES DONDE ME DA EL ERROR
TextBox1.Clear
TextBox2.Clear
ComboBox3.Clear
TextBox3.Clear
ComboBox5.Clear
ComboBox6.Clear
ComboBox7.Clear
ComboBox8.Clear
ComboBox9.Clear
ComboBox10.Clear
ComboBox11.Clear
ComboBox12.Clear
Dim nal As Single
Dim und As Single
Dim doc As Single
Dim mot As Single
Sheets("LISTAS").Visible = True
Sheets("listas").Select
und = Application.WorksheetFunction.CountA(Range("a2:a50000"))
doc = Application.WorksheetFunction.CountA(Range("b2:b50000"))
nal = Application.WorksheetFunction.CountA(Range("c2:c50000"))
mot = Application.WorksheetFunction.CountA(Range("d2:d50000"))
For und1 = 2 To und + 1
Celda = Cells(und1, 1).Value
ComboBox3.AddItem Celda
Next
For doc1 = 2 To doc + 1
Celda = Cells(doc1, 2).Value
ComboBox7.AddItem Celda
ComboBox9.AddItem Celda
ComboBox11.AddItem Celda
Next
For nal1 = 2 To nal + 1
Celda = Cells(nal1, 3).Value
ComboBox5.AddItem Celda
ComboBox8.AddItem Celda
ComboBox10.AddItem Celda
ComboBox12.AddItem Celda
Next
For mot1 = 2 To mot + 1
Celda = Cells(mot1, 4).Value
ComboBox6.AddItem Celda
Next
Sheets("LISTAS").Visible = False
Sheets("inicio").Select
End Sub
Private Sub CommandButton3_Click()
Unload Me
End Sub
Private Sub OptionButton1_Click()
If OptionButton1.Value = True Then
Sheets("listas").Visible = True
Sheets("ESTADISTICA").Visible = False
Sheets("listas").Select
End If
Unload Me
End Sub
Private Sub OptionButton2_Click()
If OptionButton2.Value = True Then
Sheets("ESTADISTICA").Visible = True
Sheets("LISTAS").Visible = False
Sheets("ESTADISTICA").Select
End If
Unload Me
End Sub
Private Sub OptionButton3_Click()
If OptionButton3.Value = True Then
Sheets("ESTADISTICA").Visible = False
Sheets("LISTAS").Visible = False
Sheets("TABLA").Select
End If
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim nal As Single
Dim und As Single
Dim doc As Single
Dim mot As Single
Sheets("listas").Visible = True
Sheets("listas").Select
und = Application.WorksheetFunction.CountA(Range("a2:a50000"))
doc = Application.WorksheetFunction.CountA(Range("b2:b50000"))
nal = Application.WorksheetFunction.CountA(Range("c2:c50000"))
mot = Application.WorksheetFunction.CountA(Range("d2:d50000"))
For und1 = 2 To und + 1
Celda = Cells(und1, 1).Value
ComboBox3.AddItem Celda
Next
For doc1 = 2 To doc + 1
Celda = Cells(doc1, 2).Value
ComboBox7.AddItem Celda
ComboBox9.AddItem Celda
ComboBox11.AddItem Celda
Next
For nal1 = 2 To nal + 1
Celda = Cells(nal1, 3).Value
ComboBox5.AddItem Celda
ComboBox8.AddItem Celda
ComboBox10.AddItem Celda
ComboBox12.AddItem Celda
Next
For mot1 = 2 To mot + 1
Celda = Cells(mot1, 4).Value
ComboBox6.AddItem Celda
Next
Sheets("listas").Visible = False
Sheets("inicio").Select
End Sub
Solicito vuestra ayuda para solucionar el problema y mejorar la
macro.
Muchas gracias
M. Ángel
Leer las respuestas