Llenar un textbox dependiendo del ítem del listbox
Quisiera una ayudita con un código ya que no doy con ninguna cosa.
Se puede hacer esto: Si hago una selección de un ListBox que tiene como ítem estos elementos "Día y Noche" quisiera saber que al seleccionar día se puede llenar un textbox automáticamente con un valor relacionado a la selección del ítem de la lista es decir si selecciono Día se llene el textbox con la palabra sol y si selecciono noche se llene el textbox con la palabra luna.

Te anexo el código
Private Sub ListBox1_Click() 'Por Dante Amor dato = ListBox1.List(ListBox1.ListIndex, 0) Select Case LCase(dato) Case LCase("Día") TextBox1.Value = "sol" Case LCase("Noche") TextBox1.Value = "luna" Case Else TextBox1.Value = "nublado" End Select End Sub
'.[Sal u dos. Dante Amor. No olvides valorar la respuesta. '.[Avísame cualquier duda
'
[
.

Buenas noches Dante, gracias por tu respuesta pero no funciona sale error 381, bueno creo que este también seria el otro caso si puede ser aplicado, que el textbox17 se ponga "Dia" el textbox18 se llene automáticamente con la palabra "Sol"
Y si se pone en el mismo textbox17 la palabra "Noche" el textbox18 se llene automáticamente con la palabra "Luna" y si así sucesivamente.
"Nota el sol y la luna solo lo pongo como ejemplo en el código de abajo son los datos reales."
Adjunto el código que quiero aplicar para que veas que estoy haciendo mal. Como notaras hay hay un segmento que trata de un listbox que funciona sin problemas.
Private Sub ListBox3_Click() TextBox17.Text = ListBox3.List(ListBox3.ListIndex) Me.ListBox3.Visible = False 'Por Dante Amor dato = ListBox3.List(ListBox3.ListIndex, 0) Select Case LCase(dato) Case LCase("CARRIER") TextBox18.Value = "R134a" Case LCase("THERMOKING") TextBox18.Value = "R404a" Case LCase("DAIKIN") TextBox18.Value = "R134a" Case LCase("STARCOOL") TextBox18.Value = "R134a" 'Case Else ' TextBox1.Value = "nublado" End Select End Sub
Gracias de antemano

¿Y qué dice el mensaje de error?
¿Y en cuál línea de la macro se detiene?
Ya probé tu código y sí me funciona.
¿Tienes otros eventos en tu userform?

Private Sub CommandButton1_Click() 'Pasas varios datos a un TextBox3 si es Texto TextBox6.Text = TextBox1.Text TextBox7.Text = TextBox2.Text TextBox8.Text = TextBox3.Text TextBox9.Text = TextBox4.Text TextBox10.Text = TextBox17.Value TextBox11.Text = TextBox19.Text TextBox12.Text = TextBox20.Text TextBox13.Text = TextBox16.Value TextBox15.Text = TextBox14.Text If TextBox1 = Empty Then MsgBox ("Debe ingresar el numero") End If If TextBox2 = Empty Then MsgBox ("Debe ingresar el modelo") End If If TextBox3 = Empty Then MsgBox ("Debe ingresar el serial") End If If TextBox4 = Empty Then MsgBox ("Debe ingresar la manufactura") End If If TextBox17 = Empty Then MsgBox ("Debe ingresar la marca") End If If Me.TextBox1.Value <> "" Then Me.CommandButton1.Enabled = True Else Me.CommandButton1.Enabled = False End If End Sub Private Sub Frame2_Click() End Sub Private Sub ListBox1_Click() TextBox14.Text = ListBox1.List(ListBox1.ListIndex) Me.ListBox1.Visible = False End Sub Private Sub ListBox2_Click() TextBox16.Text = ListBox2.List(ListBox2.ListIndex) Me.ListBox2.Visible = False End Sub Private Sub ListBox3_Click() TextBox17.Text = ListBox3.List(ListBox3.ListIndex) Me.ListBox3.Visible = False End Sub Private Sub ListBox4_Click() TextBox20.Text = ListBox4.List(ListBox4.ListIndex) Me.ListBox4.Visible = False End Sub Private Sub TextBox14_Change() Me.ListBox1.Clear For i = 2 To 13 If LCase(Range("A" & i).Value) Like LCase(TextBox14.Text) & "*" Then Me.ListBox1.Visible = True Me.ListBox1.AddItem Range("A" & i).Value End If Next End Sub Private Sub TextBox16_Change() Me.ListBox2.Clear For i = 2 To 16 If LCase(Range("C" & i).Value) Like LCase(TextBox16.Text) & "*" Then Me.ListBox2.Visible = True Me.ListBox2.AddItem Range("C" & i).Value End If Next End Sub Private Sub TextBox17_Change() Me.ListBox3.Clear For i = 2 To 9 If LCase(Range("B" & i).Value) Like LCase(TextBox17.Text) & "*" Then Me.ListBox3.Visible = True Me.ListBox3.AddItem Range("B" & i).Value End If Next 'Por Dante Amor dato = TextBox17.Text(TextBox17.Text, 0) Select Case LCase(dato) Case LCase("CARRIER") TextBox18.Value = "R134a" Case LCase("THERMOKING") TextBox18.Value = "R404a" Case LCase("DAIKIN") TextBox18.Value = "R134a" Case LCase("STARCOOL") TextBox18.Value = "R134a" 'Case Else ' TextBox1.Value = "nublado" End Select If Me.TextBox17.Value <> "" Then Me.CommandButton1.Enabled = True Else Me.CommandButton1.Enabled = False End If End Sub Private Sub TextBox2_Change() If Me.TextBox2.Value <> "" Then Me.CommandButton1.Enabled = True Else Me.CommandButton1.Enabled = False End If End Sub Private Sub TextBox20_Change() Me.ListBox4.Clear For i = 2 To 6 If LCase(Range("D" & i).Value) Like LCase(TextBox20.Text) & "*" Then Me.ListBox4.Visible = True Me.ListBox4.AddItem Range("D" & i).Value End If Next End Sub Private Sub TextBox3_Change() If Me.TextBox3.Value <> "" Then Me.CommandButton1.Enabled = True Else Me.CommandButton1.Enabled = False End If End Sub Private Sub TextBox4_Change() If Me.TextBox4.Value <> "" Then Me.CommandButton1.Enabled = True Else Me.CommandButton1.Enabled = False End If End Sub Private Sub UserForm_Initialize() TextBox19 = Date End Sub
Hola buen día adjunto código completo de este formulario y una imagen para que veas el error que tengo.
Gracias de antemano.

Pero yo puse esto:
dato = ListBox1. List(ListBox1. ListIndex, 0)
Y tu pones esto:
Dato = textbox17.text(textbox17.text, 0)
Eso no puede ser, porque son controles diferentes. El texbox no tiene esa propiedad, por eso te envía error de argumentos.
Esto es lo que pediste:
Si hago una selección de un ListBox que tiene como ítem estos elementos "Día y Noche" quisiera saber que al seleccionar día se puede llenar un textbox
Ahora ya no sé qué necesitas.
Para ver el funcionamiento del listbox y el textbox, realiza lo siguiente.
Crea un form con un listbox1 y un textbox1
Pones el siguiente código en el userform
Private Sub ListBox1_Click() 'Por Dante Amor dato = ListBox1.List(ListBox1.ListIndex, 0) Select Case LCase(dato) Case LCase("CARRIER") TextBox1.Value = "R134a" Case LCase("THERMOKING") TextBox1.Value = "R404a" Case LCase("DAIKIN") TextBox1.Value = "R134a" Case LCase("STARCOOL") TextBox1.Value = "R134a" End Select End Sub ' Private Sub UserForm_Activate() ListBox1. AddItem "CARRIER" ListBox1. AddItem "THERMOKING" ListBox1. AddItem "DAIKIN" ListBox1. AddItem "STARCOOL" End Sub
Ejecuta el form, selecciona un registro del listbox. Verás como en automático se llena el textbox.
Eso es lo que pediste. Lo demás deberás crear una nueva pregunta y explicar con ejemplos qué necesitas.
- Compartir respuesta
