Excel - Error en el método

 
Vista:

Error en el método

Publicado por Ericka Alejandra (2 intervenciones) el 29/11/2023 22:37:32
Hola, estoy usando este código de buscar en una hoja para cargar los datos en el formulario pero desde la primera línea después del for me da ese error... ¿Qué podría hacer? ¡Gracias!


Private Sub Cedula_AlumnoTXT_AfterUpdate()
Dim filafinal As String
Dim encontrar As Boolean

If Cedula_AlumnoTXT.Value <> vbNullString And IsNumeric(Cedula_AlumnoTXT.Value) = False Then
MsgBox ("Los datos ingresados deben ser de carácter numérico, por favor verifique y vuelva a intentarlo.")
Cedula_AlumnoTXT.Value = ""
Else

Worksheets("Registro de Pagos").Activate
filafinal = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
encontrar = False
For i = 2 To filafinal
If Cedula_AlumnoTXT.Value = Range("A" & fila).Value Then
Nombre_AlumnoTxt.Value = Range("B" & i).Value
PrimerApellido_AlumnoTxt.Value = Range("C" & i).Value
Segundo_ApellidoAlumnoTxt.Value = Range("D" & i).Value
BloqueHorariosCMB.Value = Range("F" & i).Value
NumerodiasSemanaCMB.Value = Range("G" & i).Value
MontoCancelarMesTXT.Value = Range("H" & i).Value
ValorMatriculaTXT.Value = Range("I" & i).Value
MaterialesSemes1TXT.Value = Range("J" & i).Value
MaterialesSemes2TXT.Value = Range("K" & i).Value
FormaPagoCMB.Value = Range("L" & i).Value
EstadoPagoCMB.Value = Range("M" & i).Value
MontoCancelarTXT.Value = Range("N" & i).Value
ElseIf Range("E" & i).Value = "Mensual" Then
HorarioMensualOPC.Value = True
Else
HorarioSemanalOPC.Value = False
AgregarPagosCB.Enabled = True
ModificarPagosCB.Enabled = False
encontrar = True
Exit For
End If
Next

If encontrar = False Then
Cedula_AlumnoTXT.Value = ""
Nombre_AlumnoTxt.Value = ""
PrimerApellido_AlumnoTxt.Value = ""
Segundo_ApellidoAlumnoTxt.Value = ""
BloqueHorariosCMB.ListIndex = -1
NumerodiasSemanaCMB.ListIndex = -1
MontoCancelarMesTXT.Value = ""
ValorMatriculaTXT.Value = ""
MaterialesSemes1TXT.Value = ""
MaterialesSemes2TXT.Value = ""
FormaPagoCMB.ListIndex = -1
EstadoPagoCMB.ListIndex = -1
MontoCancelarTXT.Value = ""
HorarioMensualOPC.Value = False
HorarioSemanalOPC.Value = False
ModificarPagosCB.Enabled = False
AgregarPagosCB.Enabled = True
End If
End If
End Sub
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Error en el método 'Range' de objeto '_Global'

Publicado por ERICKA ESQUIVEL (2 intervenciones) el 29/11/2023 22:59:06
Se ha producido el error '1004' en tiempo de ejecución:
Error en el método 'Range' de objeto '_Global'
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Antoni Masana
Val: 4.908
Oro
Ha mantenido su posición en Excel (en relación al último mes)
Gráfica de Excel

Error en el método 'Range' de objeto '_Global'

Publicado por Antoni Masana (2478 intervenciones) el 30/11/2023 14:26:12
Primero se lee mejor así, funcionar funciona igual.

La explicación en el código.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Private Sub Cedula_AlumnoTXT_AfterUpdate()
    Dim filafinal As String
    Dim encontrar As Boolean
 
    If Cedula_AlumnoTXT.Value <> vbNullString And IsNumeric(Cedula_AlumnoTXT.Value) = False Then
        MsgBox ("Los datos ingresados deben ser de carácter numérico, por favor verifique y vuelva a intentarlo.")
        Cedula_AlumnoTXT.Value = ""
    Else
        Worksheets("Registro de Pagos").Activate
        filafinal = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
        encontrar = False
        For i = 2 To filafinal
 
             ' ---------------- El error esta aqui: vvvv
            If Cedula_AlumnoTXT.Value = Range("A" & fila).Value Then   ' <--- la variable fila no esta definida
                                                                       '      y no tiene valor.
 
                Nombre_AlumnoTxt.Value = Range("B" & i).Value
                PrimerApellido_AlumnoTxt.Value = Range("C" & i).Value
                Segundo_ApellidoAlumnoTxt.Value = Range("D" & i).Value
                BloqueHorariosCMB.Value = Range("F" & i).Value
                NumerodiasSemanaCMB.Value = Range("G" & i).Value
                MontoCancelarMesTXT.Value = Range("H" & i).Value
                ValorMatriculaTXT.Value = Range("I" & i).Value
                MaterialesSemes1TXT.Value = Range("J" & i).Value
                MaterialesSemes2TXT.Value = Range("K" & i).Value
                FormaPagoCMB.Value = Range("L" & i).Value
                EstadoPagoCMB.Value = Range("M" & i).Value
                MontoCancelarTXT.Value = Range("N" & i).Value
            ElseIf Range("E" & i).Value = "Mensual" Then
                HorarioMensualOPC.Value = True
            Else
                HorarioSemanalOPC.Value = False
                AgregarPagosCB.Enabled = True
                ModificarPagosCB.Enabled = False
                encontrar = True
                Exit For
            End If
        Next
 
        If encontrar = False Then
            Cedula_AlumnoTXT.Value = ""
            Nombre_AlumnoTxt.Value = ""
            PrimerApellido_AlumnoTxt.Value = ""
            Segundo_ApellidoAlumnoTxt.Value = ""
            BloqueHorariosCMB.ListIndex = -1
            NumerodiasSemanaCMB.ListIndex = -1
            MontoCancelarMesTXT.Value = ""
            ValorMatriculaTXT.Value = ""
            MaterialesSemes1TXT.Value = ""
            MaterialesSemes2TXT.Value = ""
            FormaPagoCMB.ListIndex = -1
            EstadoPagoCMB.ListIndex = -1
            MontoCancelarTXT.Value = ""
            HorarioMensualOPC.Value = False
            HorarioSemanalOPC.Value = False
            ModificarPagosCB.Enabled = False
            AgregarPagosCB.Enabled = True
        End If
    End If
End Sub

Saludos.
\\//_
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar