Error de compilación: Se esperaba una matriz

Tengo una macro en que entre las Xs es del amigo Dante

Private Sub CommandButton1_Click() 'Saving Button
Dim sonsat As Long
'XXXX
Dim vcS As String
Dim vtx As String
Dim i As Double
Application.ScreenUpdating = False
'1º Array de nombre de control
    vcS = Array("Textbox1", "Textbox2", "Textbox3", "Textbox4", "TextBox5", "TextBox6", "TextBox8")
'2º Array de mensaje a presentar segun el orden de los controles
    vtx = Array("Minimo 1º Nombre y 1º apellido", "Nombre de compañia", "Dirección de residencia", _
    "Ciudad", "País de Residencia", "El Estado", "El # de Teléfono")
    For i = LBound(vcS) To UBound(vcS)  'ME MARCA EN LBound
        If Controls(vcS(i)) = Empty Then
            MsgBox "DEBES INTRODUCIR: " & vtx(i), vbExclamation, "ALTA"
            Exit Sub
        End If
    Next
'XXXXX    If Not IsNumeric(TextBox12.Text) Then
        MsgBox "Please enter a Numeric Value.", vbExclamation
        TextBox12.SetFocus
        Exit Sub
    End If
sonsat = Sheets("Data").[a65536].End(3).Row + 1
Call Main 'Progress Bar
Cells(sonsat, 1) = TextBox1
Cells(sonsat, 2) = TextBox2
Cells(sonsat, 3) = TextBox3
Cells(sonsat, 4) = TextBox4
Cells(sonsat, 5) = TextBox5
Cells(sonsat, 6) = TextBox6
Cells(sonsat, 7) = TextBox7
Cells(sonsat, 8) = TextBox8
Cells(sonsat, 9) = TextBox9
Cells(sonsat, 10) = TextBox10
Cells(sonsat, 11) = TextBox11
Cells(sonsat, 12) = TextBox12
MsgBox "Registro completo
ListBox1.List = Sheets("Data").Range("a2:l" & [a65536].End(3).Row).Value 'For refresh listbox
TextBox14.Value = ListBox1.ListCount
Application.ScreenUpdating = True
End Sub

Al inicio de la macro es para no dejar esos controles vacíos al introducir los datos.

Me manda el error en línea For i = LBound(vcS) To UBound(vcS) marcando LBound, no se que hacer

Agradecido por su generosa ayuda

1 Respuesta

Respuesta
1

El problema es la declaración de la variable

VcS

No te preocupes por declarar las variables, en VBA no es necesario declararlas.

Si no la hubieras declarado, tu macro no tendría problemas.

Deja el código así:

Private Sub CommandButton1_Click() 'Saving Button
    Application.ScreenUpdating = False
    '1º Array de nombre de control
    vcS = Array("Textbox1", "Textbox2", "Textbox3", "Textbox4", "TextBox5", "TextBox6", "TextBox8")
    '2º Array de mensaje a presentar segun el orden de los controles
    vtx = Array("Minimo 1º Nombre y 1º apellido", "Nombre de compañia", "Dirección de residencia", _
    "Ciudad", "País de Residencia", "El Estado", "El # de Teléfono")
    For i = LBound(vcS) To UBound(vcS)  'ME MARCA EN LBound
        If Controls(vcS(i)) = Empty Then
            MsgBox "DEBES INTRODUCIR: " & vtx(i), vbExclamation, "ALTA"
            Exit Sub
        End If
    Next
    If Not IsNumeric(TextBox12.Text) Then
        MsgBox "Please enter a Numeric Value.", vbExclamation
        TextBox12.SetFocus
        Exit Sub
    End If
    sonsat = Sheets("Data").[a65536].End(3).Row + 1
    Call Main 'Progress Bar
    Cells(sonsat, 1) = TextBox1
    Cells(sonsat, 2) = TextBox2
    Cells(sonsat, 3) = TextBox3
    Cells(sonsat, 4) = TextBox4
    Cells(sonsat, 5) = TextBox5
    Cells(sonsat, 6) = TextBox6
    Cells(sonsat, 7) = TextBox7
    Cells(sonsat, 8) = TextBox8
    Cells(sonsat, 9) = TextBox9
    Cells(sonsat, 10) = TextBox10
    Cells(sonsat, 11) = TextBox11
    Cells(sonsat, 12) = TextBox12
    MsgBox "Registro completo"
    ListBox1.List = Sheets("Data").Range("a2:l" & [a65536].End(3).Row).Value 'For refresh listbox
    TextBox14.Value = ListBox1.ListCount
    Application.ScreenUpdating = True
End Sub

Si la siguiente pregunta es, cómo se debe declarar, entonces la declaras así:

Dim vcS()

sal u dos

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas