Problemas con listbox en VBA excel
tengo dos form:
- en form entrada, elijo un valor de cada listbox (son 5) y lo asigno a una celda
- en form modificar, deseo recuperar los valores ingresados, mostrarlos en el mismo formato que se ingresaron y ofrecer la oportunidad de cambiarlo
funciona en 3 de 5 de ellos, a pesar que están las instrucciones están codificadas exactamente igual, solo cambié el nombre del list box
Ingreso de datos
Private Sub UserForm_activate()
supervisor.Clear
Ubic = "a2"
Range(Ubic).Select
Do While ActiveCell <> Empty
supervisor.AddItem ActiveCell
ActiveCell.Offset(1, 0).Select
Loop
perforadora.Clear
Ubic = "b2"
Range(Ubic).Select
Do While ActiveCell <> Empty
perforadora.AddItem ActiveCell
ActiveCell.Offset(1, 0).Select
Loop
perforista.Clear
Ubic = "c2"
Range(Ubic).Select
Do While ActiveCell <> Empty
perforista.AddItem ActiveCell
ActiveCell.Offset(1, 0).Select
Loop
pozo.Clear
Ubic = "d2"
Range(Ubic).Select
Do While ActiveCell <> Empty
pozo.AddItem ActiveCell
ActiveCell.Offset(1, 0).Select
Loop
proyecto.Clear
Ubic = "e2"
Range(Ubic).Select
Do While ActiveCell <> Empty
proyecto.AddItem ActiveCell
ActiveCell.Offset(1, 0).Select
Loop
End Sub
Modificar datos
Private Sub UserForm_activate()
supervisor.Clear
Ubic = "a2"
Range(Ubic).Select
Do While ActiveCell <> Empty
supervisor.AddItem ActiveCell
ActiveCell.Offset(1, 0).Select
Loop
perforadora.Clear
Ubic = "b2"
Range(Ubic).Select
Do While ActiveCell <> Empty
perforadora.AddItem ActiveCell
ActiveCell.Offset(1, 0).Select
Loop
perforista.Clear
Ubic = "c2"
Range(Ubic).Select
Do While ActiveCell <> Empty
perforista.AddItem ActiveCell
ActiveCell.Offset(1, 0).Select
Loop
pozo.Clear
Ubic = "d2"
Range(Ubic).Select
Do While ActiveCell <> Empty
pozo.AddItem ActiveCell
ActiveCell.Offset(1, 0).Select
Loop
proyecto.Clear
Ubic = "e2"
Range(Ubic).Select
Do While ActiveCell <> Empty
proyecto.AddItem ActiveCell
ActiveCell.Offset(1, 0).Select
Loop
For i = 0 To supervisor.ListCount - 1
If supervisor.List(i) = Worksheets("hoja1").Cells(15, 1).Value Then
supervisor.Selected(i) = True
End If
Next i
For i = 0 To perforadora.ListCount - 1
If perforadora.List(i) = Worksheets("hoja1").Cells(15, 2).Value Then
perforadora.Selected(i) = True
End If
Next i
For i = 0 To perforista.ListCount - 1
If perforista.List(i) = Worksheets("hoja1").Cells(15, 3).Value Then
perforista.Selected(i) = True
End If
Next i
For i = 0 To pozo.ListCount - 1
If pozo.List(i) = Worksheets("hoja1").Cells(15, 4).Value Then
pozo.Selected(i) = True
End If
Next i
For i = 0 To proyecto.ListCount - 1
If proyecto.List(i) = Worksheets("hoja1").Cells(15, 5).Value Then
proyecto.Selected(i) = True
End If
Next i
End Sub
Private Sub supervisor_Click()
Worksheets("hoja1").Range("a15").Select
ActiveCell.Value = supervisor
End Sub
Private Sub perforadora_Click()
Worksheets("hoja1").Range("b15").Select
ActiveCell.Value = perforadora
End Sub
Private Sub perforista_Click()
Worksheets("hoja1").Range("c15").Select
ActiveCell.Value = perforista
End Sub
Private Sub pozo_Click()
Worksheets("hoja1").Range("d15").Select
ActiveCell.Value = pozo
End Sub
Private Sub proyecto_Click()
Worksheets("hoja1").Range("e15").Select
ActiveCell.Value = proyecto
End Sub