Erro al compilar un programa. Datos en los combobox

Buenos días y gracias de antemano. Tengo un problema en un programilla que estoy haciendo, me sale este error cuando compilo el programa. Esto es ñp que tengo
Private Sub Guardar_Click()
   Dim x, y, z, v, w, q, r, s, t, p As Integer
   If ComboBox1.Text = "" Then Salida2
            Else
            If ComboBox2.Text = "" Then
            MsgBox ("No ha seleccionado modelo en Salida 1, compruebe los datos")
            Exit Sub
            x = Choose(ComboBox1.ListIndex + 1, 4, 13, 23, 33, 43, 50, 57, 64, 71, 78, 84, 90, 96, 102, 108, 128, 139, 148, 156, 171, 183, 193, 204, 212, 222, 265, 275, 280, 285, 308, 336, 344, 369, 378) + ComboBox2.ListIndex
            Sheets("Datos").Cells(x, 4) = Sheets("Datos").Cells(x, 4) - SalidaMaterial.TextBox2.Value
            ActiveWorkbook.Save
            ComboBox2.Text = ""
            TextBox2 = Empty
            End If
    End If
Sub Salida2()
        If ComboBox4.Text = "" Then GoTo Salida3
        Else
            If ComboBox3.Text = "" Then
            MsgBox ("No ha seleccionado modelo en Salida 2, compruebe los datos")
            Exit Sub
            y = Choose(ComboBox4.ListIndex + 1, 4, 13, 23, 33, 43, 50, 57, 64, 71, 78, 84, 91, 96, 102, 108, 128, 139, 148, 156, 171, 183, 193, 204, 212, 222, 265, 275, 280, 285, 308, 336, 344, 369, 378) + ComboBox3.ListIndex
            Sheets("Datos").Cells(y, 4) = Sheets("Datos").Cells(y, 4) - SalidaMaterial.TextBox3.Value
            ActiveWorkbook.Save
            ComboBox3.Text = ""
            TextBox3 = Empty
            End If
        End If
    End Sub
Lo que quiero es que si el ComboBox1 esta vacío pase a la Salida2 y sino siga ejecutando las siguientes instrucciones. Es la solución que he pensado, el tema es que tengo 20 ComboBox y sino pongo un dato en laguno de ellos me da error, y yo quiero que pueda usar el que me parezca.
Haber si puedes ayudarme.
Un saludo.
Respuesta
1
El error es porque desde el principio estás usando un IF y lo estás finalizando en la misma línea de texto.
Ejemplo:  If ComboBox1.Text = "" then Goto Salida2 'aquí termina el If
else
'El programa buscará donde comenzó el If para este "Else"
 
Tu código debería quedar así:
Private Sub Guardar_Click()
   Dim x, y, z, v, w, q, r, s, t, p As Integer
   If ComboBox1.Text = "" Then
 Salida2
            Else
            If ComboBox2.Text = "" Then
            MsgBox ("No ha seleccionado modelo en Salida 1, compruebe los datos")
            Exit Sub
            x = Choose(ComboBox1. ListIndex + 1, 4, 13, 23, 33, 43, 50, 57, 64, 71, 78, 84, 90, 96, 102, 108, 128, 139, 148, 156, 171, 183, 193, 204, 212, 222, 265, 275, 280, 285, 308, 336, 344, 369, 378) + ComboBox2. ListIndex
            Sheets("Datos").Cells(x, 4) = Sheets("Datos").Cells(x, 4) - SalidaMaterial.TextBox2.Value
            ActiveWorkbook.Save
            ComboBox2.Text = ""
            TextBox2 = Empty
            End If
    End If
Sub Salida2()
        If ComboBox4.Text = "" Then
 GoTo Salida3
        Else
            If ComboBox3.Text = "" Then
            MsgBox ("No ha seleccionado modelo en Salida 2, compruebe los datos")
            Exit Sub
            y = Choose(ComboBox4. ListIndex + 1, 4, 13, 23, 33, 43, 50, 57, 64, 71, 78, 84, 91, 96, 102, 108, 128, 139, 148, 156, 171, 183, 193, 204, 212, 222, 265, 275, 280, 285, 308, 336, 344, 369, 378) + ComboBox3. ListIndex
            Sheets("Datos").Cells(y, 4) = Sheets("Datos").Cells(y, 4) - SalidaMaterial.TextBox3.Value
            ActiveWorkbook.Save
            ComboBox3.Text = ""
            TextBox3 = Empty
            End If
        End If
Salida3:
    End Sub
Espero esto te ayude, de lo contrario encontraremos otra solución...

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas