Colocar un guión a un textbox

Buenas dias, por favor me puede decir, como hago para colocar un guión a un textbox que no haya se le haya introducido informacion, me explico: Resulta que tengo un userform donde voy a capturar 7 textbox´s, cuya información son observaciones que se hacen (esto corresponde a los 7 dias de la semana), puede ser que hayan observaciones, como no, pero si no hay debo colocar un guión o un asterisco, no puede quedar en blanco esa celda cuyo textbox no obtuvo informacion. Te muestro como tengo mi macro: Hasta aqui funciona bien.
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim fila As Integer
fila = 9
While Cells(fila, 23) <> Empty
fila = fila + 1
Wend
Cells(fila, 23) = TextBox1
Cells(fila + 1, 23) = TextBox2
Cells(fila + 2, 23) = TextBox3
Cells(fila + 3, 23) = TextBox4
Cells(fila + 4, 23) = TextBox5
Cells(fila + 5, 23) = TextBox6
Cells(fila + 6, 23) = TextBox7
End
If TextBox1.Text = " " Then Cells(fila, 23) = "-" Else Cells(fila, 23) = TextBox1
If TextBox2.Text = " " Then Cells(fila + 1, 23) = "-" Else Cells(fila, 23) = TextBox2
If TextBox3.Text = " " Then Cells(fila + 2, 23) = "-" Else Cells(fila, 23) = TextBox3
If TextBox4.Text = " " Then Cells(fila + 3, 23) = "-" Else Cells(fila, 23) = TextBox4
If TextBox5.Text = " " Then Cells(fila + 4, 23) = "-" Else Cells(fila, 23) = TextBox5
If TextBox6.Text = " " Then Cells(fila + 5, 23) = "-" Else Cells(fila, 23) = TextBox6
If TextBox7.Text = " " Then Cells(fila + 6, 23) = "-" Else Cells(fila, 23) = TextBox7
TextBox1 = Empty
TextBox2 = Empty
TextBox3 = Empty
TextBox4 = Empty
TextBox5 = Empty
TextBox6 = Empty
TextBox7 = Empty
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
Respuesta
1
Añade etas lineas a tu macro :
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If TextBox1 = "" Then TextBox1 = "-"
End Sub
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If TextBox2 = "" Then TextBox2 = "-"
End Sub
Private Sub TextBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If TextBox3 = "" Then TextBox3 = "-"
End Sub
Private Sub TextBox4_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If TextBox4 = "" Then TextBox4 = "-"
End Sub
Private Sub TextBox5_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If TextBox5 = "" Then TextBox5 = "-"
End Sub
Private Sub TextBox6_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If TextBox6 = "" Then TextBox6 = "-"
End Sub
Private Sub TextBox7_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If TextBox7 = "" Then TextBox7 = "-"
End Sub
Y modifica estas lineas de tu macro asi :
If TextBox1.Text = " " Then Cells(fila, 23) = "-" Else Cells(fila, 23) = TextBox1
If TextBox2.Text = " " Then Cells(fila + 1, 23) = "-" Else Cells(fila, 23) = TextBox2
If TextBox3.Text = " " Then Cells(fila + 2, 23) = "-" Else Cells(fila, 23) = TextBox3
If TextBox4.Text = " " Then Cells(fila + 3, 23) = "-" Else Cells(fila, 23) = TextBox4
If TextBox5.Text = " " Then Cells(fila + 4, 23) = "-" Else Cells(fila, 23) = TextBox5
If TextBox6.Text = " " Then Cells(fila + 5, 23) = "-" Else Cells(fila, 23) = TextBox6
If TextBox7.Text = " " Then Cells(fila + 6, 23) = "-" Else Cells(fila, 23) = TextBox7
Por estas:
Cells(fila, 23) = TextBox1
Cells(fila, 23) = TextBox2
Cells(fila, 23) = TextBox3
Cells(fila, 23) = TextBox4
Cells(fila, 23) = TextBox5
Cells(fila, 23) = TextBox6
Cells(fila, 23) = TextBox7

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas