Finalizacion Rutina IF

14/09/2006 - 04:53 por SantiRv | Informe spam
Hola:
Estoy renegando (perdiendo mucho timepo) con una rutina sencilla que me
permita cargar datos de un formulario a una hoja especifica de excel.
La cuestion radica en que ciertos textbox deben ser llenados si o si
Paso la sentencia para que me digan que tengo que hacer para que si no
cumple con alguno no carge los datos ingresados; por ende si los cumple
que si lo haga
Desde Ya gracias

Private Sub CommandButton1_Click()

If TextBox2.Text = "" Then
MsgBox "Se debe introducir un Nombre"
TextBox2.SetFocus
Else
If TextBox3.Text = "" Then
MsgBox "Se debe introducir una Dirección"
TextBox3.SetFocus
Else
If ComboBox1.Text = "" Then
MsgBox "Se debe introducir Localidad"
ComboBox1.SetFocus

End If
End If

End If
Exit Sub
Sheets("CLIENTES").Activate
NextRow = Application.WorksheetFunction.CountA(Range("B:B")) + 1
Cells(NextRow, 1) = TextBox1.Text
Cells(NextRow, 2) = TextBox2.Text
Cells(NextRow, 3) = TextBox3.Text
Cells(NextRow, 4) = TextBox4.Text
Cells(NextRow, 5) = TextBox5.Text
Cells(NextRow, 6) = ComboBox1.Text
Cells(NextRow, 7) = TextBox6.Text
Sheets("MENU").Activate

CommandButton1.Visible = False
 

Leer las respuestas

#1 Héctor Miguel
14/09/2006 - 06:22 | Informe spam
hola, Santiago !

Mostrar la cita
1) necesitas revisar con 'vista' [un poquitin mas]... 'logica' y entender que la instruccion 'Exit Sub' esta evitando que el codigo continue...
-> independientemente de si se cumplen o no, las instrucciones If...Then que tienes antes de la salida del procedimiento :))

2) puedes utilizar tres instrucciones If...Then 'separadas' -> cada una con su 'Exit Sub' en caso de no cumplirse la condicion...
o puedes agregar una variable [p.e.] que vaya 'contando' las condiciones cumplidas y... si se cumplen las 3... el codigo continua ;)

3) tambien podrias 'mover' las instrucciones para que SI se ejecuten, agregando un 'Else' al tercer bloque 'If...Then'
ya que de cumplirse la tercer condicionante... [se supone que] se habran cumplido tambien las anteriores ;)

si cualquier duda [o informacion adicional]... comentas ?
saludos,
hector.

__ el codigo expuesto __
Private Sub CommandButton1_Click()
If TextBox2.Text = "" Then
MsgBox "Se debe introducir un Nombre"
TextBox2.SetFocus
Else
If TextBox3.Text = "" Then
MsgBox "Se debe introducir una Dirección"
TextBox3.SetFocus
Else
If ComboBox1.Text = "" Then
MsgBox "Se debe introducir Localidad"
ComboBox1.SetFocus
End If
End If
End If
Exit Sub
Sheets("CLIENTES").Activate
NextRow = Application.WorksheetFunction.CountA(Range("B:B")) + 1
Cells(NextRow, 1) = TextBox1.Text
Cells(NextRow, 2) = TextBox2.Text
Cells(NextRow, 3) = TextBox3.Text
Cells(NextRow, 4) = TextBox4.Text
Cells(NextRow, 5) = TextBox5.Text
Cells(NextRow, 6) = ComboBox1.Text
Cells(NextRow, 7) = TextBox6.Text
Sheets("MENU").Activate
CommandButton1.Visible = False

Preguntas similares