Como solucionar error en vba

Espero puedan ayudarme tengo este código

'Abrir el formulario para modificar
Private Sub CommandButton3_Click()
If Me.ListBox1.ListIndex < 0 Then
MsgBox "No se ha elegido ningún registro", vbExclamation, "EXCELeINFO"
Else

MsgBox "abriendo", vbExclamation, "EXCELeINFO"
frmModificar.Show
End If
End Sub

pero me marca error al querer abrir el formulario,

2 respuestas

Respuesta
2

Puedes poner aquí todo tu código. Utiliza el icono para insertar código.

No puedo descargar archivos.

Pon aquí el código e indicas en cuál línea te marca el error.

'Cambia el TextBox con cada cambio en el Combo
'
Private Sub cmbEncabezado_Change()
Me.lblFiltro = "Filtro por " & Me.cmbEncabezado.Value
End Sub
'
'Cerrar formulario
Private Sub CommandButton2_Click()
Unload Me
End Sub
'Abrir el formulario para modificar
Private Sub CommandButton3_Click()
If Me.ListBox1.ListIndex < 0 Then
    MsgBox "No se ha elegido ningún registro", vbExclamation, "EXCELeINFO"
Else
   UserForm2.Show
End If
End Sub
'
'Eliminar el registro
Private Sub CommandButton4_Click()
    Pregunta = MsgBox("Está seguro de eliminar el registro?", vbYesNo + vbQuestion, "EXCELeINFO")
    If Pregunta <> vbNo Then
        ActiveCell.EntireRow.Delete
        '        Fila = Me.ListBox1.ListIndex + 2
        '        Rows(Fila).Delete
        '        Application.ScreenUpdating = True
    End If
End Sub
'
'
'Mostrar resultado en ListBox
Private Sub CommandButton5_Click()
Set h1 = Sheets("DISTRIBUCION")
    Set h2 = Sheets("Temporal")
If Me.txtFiltro1.Value = "" Then Exit Sub
h2.Cells.Clear
    ListBox1.RowSource = ""
    h1.Rows(1).Copy h2.Rows(1)
Columna = Me.cmbEncabezado.ListIndex
j = cmbEncabezado.ListIndex + 1
    n = 2
    '
    For i = 1 To Range("a1").CurrentRegion.Rows.Count
        If LCase(Cells(i, j)) Like "*" & LCase(txtFiltro1) & "*" Then
            h1.Rows(i).Copy h2.Rows(n)
            n = n + 1
        End If
    Next i
    u = Range("A" & Rows.Count).End(xlUp).Row
    If u = 1 Then
        MsgBox "No existen registros con ese filtro", vbExclamation, "FILTRO"
        Exit Sub
    End If
    ListBox1.RowSource = h2.Name & "!A2:Z" & u
End Sub
Private Sub CommandButton6_Click()
UserForm1.Show
End Sub
Private Sub CommandButton7_Click()
frm_colocacion.Show
Me.Hide
End Sub
'
'Activar la celda del registro elegido
Private Sub ListBox1_Click()
Range("a1").Activate
Cuenta = Me.ListBox1.ListCount
Set Rango = Range("A1").CurrentRegion
For i = 0 To Cuenta - 1
If Me.ListBox1.Selected(i) Then
Valor = Me.ListBox1.List(i)
Rango.Find(What:=Valor, LookAt:=xlWhole, After:=ActiveCell).Activate
End If
Next i
End Sub
'
'Dar formato al ListBox y traer los encabezados de la tabla
Private Sub UserForm_Initialize()
'
For i = 1 To 14
    Me.Controls("Label" & i) = Cells(1, i).Value
Next i
'
[A1].Select
With Me
    .ListBox1.ColumnCount = 14
    .ListBox1.ColumnWidths = "80 pt;80 pt;80 pt;80 pt;80 pt;80 pt;80 pt;80 pt;80 pt;80 pt;80 pt;80 pt;80 pt;80"
    .ListBox1.ColumnHeads = True
    .cmbEncabezado.List = Application.Transpose(ActiveCell.CurrentRegion.Resize(1).Value)
    .cmbEncabezado.ListStyle = fmListStyleOption
End With
End Sub
'Actualizar el registro
Private Sub CommandButton1_Click()
For i = 1 To 14
        ActiveCell.Offset(0, i - 1).Value = Me.Controls("TextBox" & i).Value
Next i
Unload Me
End Sub
'
'Cerrar formulario
Private Sub CommandButton3_Click()
Unload Me
End Sub
Private Sub TextBox1_Change()
End Sub
 '
'Llenar los cuadro de texto con los datos del registro elegido
Private Sub UserForm_Click()
 f = ActiveCell.Row
    TextBox1 = Cells(f, "A")
    TextBox2 = Cells(f, "B")
    TextBox3 = Cells(f, "C")
    TextBox4 = Cells(f, "D")
    TextBox14 = Cells(f, "E") esta me marca error.
    TextBox5 = Cells(f, "F")
    TextBox6 = Cells(f, "G")
    TextBox7 = Cells(f, "H")
    TextBox8 = Cells(f, "I")
    TextBox9 = Cells(f, "J")
    TextBoX10 = Cells(f, "K")
    TextBox11 = Cells(f, "L")
    TextBox12 = Cells(f, "M")
    TextBox13 = Cells(f, "N")
End Sub

El problema al pasar los datos de la celda al textbox, es por que en la celda tienes algún error  (#N/A, #¡VALOR!, #¡REF!, #¿NOMBRE?, #¡DIV/O!, #¡NUM!) 

Utiliza lo siguiente para solucionarlo:

  If Not IsError(Cells(f, "E")) Then
    TextBox14 = Cells(f, "E")
  End If

Funcionó de mravilla, pero ahora me arrojo este error

Mostrar resultado en ListBox
Private Sub CommandButton5_Click()
    Set h1 = Sheets("Sheet14") error
    Set h2 = Sheets("Temporal")
    '
    If Me.txtFiltro1.Value = "" Then Exit Sub
    If cmbEncabezado = "" Then Exit Sub
    '
    h2.Cells.Clear
    ListBox1.RowSource = ""
    h1.Rows(1).Copy h2.Rows(1)
    '
    j = cmbEncabezado.ListIndex + 1
    n = 2
    '
    For i = 2 To Range("a1").CurrentRegion.Rows.Count
        If LCase(Cells(i, j)) Like "*" & LCase(txtFiltro1) & "*" Then
            h1.Rows(i).Copy h2.Rows(n)
            n = n + 1
        End If
    Next i
    u = Range("A" & Rows.Count).End(xlUp).Row
    If u = 1 Then
        MsgBox "No existen registros con ese filtro", vbExclamation, "FILTRO"
        Exit Sub
    End If
    ListBox1.RowSource = h2.Name & "!A2:Z" & u
End Sub

¿Cuál error y en cuál línea?

Eso corresponde a otro código, podrías crear una nueva pregunta y proporcionas todo el detalle.

Respuesta
1

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas