Modificar cargando todo list y combo

Te explico necsito cargar todos los datos tal cual como esta en la foto, al tener el seleccionado en el listbox me pueda cargar los campos de abajo, de tal forma que, al cargarlos y poder cambiar los datos por ejemplo de turno A sea C o la hora de 14:30 a 15:30. Te muestro imagen

1 Respuesta

Respuesta
1

Envíame tu archivo con este formulario para adaptar la macro

Lo envié ayer,atento a respuesta

Te anexo la primera parte : Llenar los campos cuando seleccionas un registro del Listbox

Dim h1
'
Private Sub CommandButton3_Click()
'Por.Dante Amor
'Filtra por turno
    If h1.AutoFilterMode Then h1.AutoFilterMode = False
    ListBox1.Clear
    ComboBox4 = ""  'ptr
    TextBox2 = ""  'ubic
    TextBox3 = ""  'equi
    TextBox4 = ""   'hi
    TextBox5 = ""   'ht
    TextBox1 = ""   'desc
    '
    If ComboBox3.Value = "" Then
        MsgBox "Seleccione un Turno"
        Exit Sub
    End If
    If ComboBox1.Value = "" Then
        fec1 = ""
    Else
        fec1 = CDate(ComboBox1.Value)
    End If
    If ComboBox2 = "" Then
        fec2 = fec1
    Else
        fec2 = CDate(ComboBox2.Value)
    End If
    '
    u = h1.Range("E" & Rows.Count).End(xlUp).Row
    lamisma = False
    For i = 3 To u
        If fec1 = "" Then fec1 = h1.Cells(i, "E"): lamisma = True
        If fec2 = "" Then fec2 = h1.Cells(i, "E")
        If h1.Cells(i, "E").Value >= fec1 And h1.Cells(i, "E") <= fec2 And _
           h1.Cells(i, "A") = ComboBox3.Value Then
            ListBox1. AddItem h1.Cells(i, "A")
            ListBox1. List(ListBox1.ListCount - 1, 1) = h1.Cells(i, "B")
            ListBox1. List(ListBox1.ListCount - 1, 2) = h1.Cells(i, "C")
            ListBox1. List(ListBox1.ListCount - 1, 3) = h1.Cells(i, "D")
            ListBox1. List(ListBox1.ListCount - 1, 4) = h1.Cells(i, "E")
            ListBox1. List(ListBox1.ListCount - 1, 5) = Format(h1.Cells(i, "F"), "hh:mm")
            ListBox1. List(ListBox1.ListCount - 1, 6) = Format(h1.Cells(i, "G"), "hh:mm")
            ListBox1. List(ListBox1.ListCount - 1, 7) = h1.Cells(i, "H")
            ListBox1.List(ListBox1.ListCount - 1, 8) = i    'cargar el número de fila de la hoja
        End If
        If lamisma Then
            fec1 = ""
            fec2 = ""
        End If
    Next
End Sub
Private Sub ListBox1_Click()
'Por.Dante Amor
    'Cargar los campos
    fila = ListBox1.List(ListBox1.ListIndex, 8)
    ComboBox4 = h1.Cells(fila, "B") 'ptr
    TextBox2 = h1.Cells(fila, "C")  'ubic
    TextBox3 = h1.Cells(fila, "D")  'equi
    TextBox4 = Format(h1.Cells(fila, "F"), "hh:mm")  'hi
    TextBox5 = Format(h1.Cells(fila, "G"), "hh:mm")  'ht
    TextBox1 = h1.Cells(fila, "H")  'desc
End Sub
'
Private Sub UserForm_Initialize()
    Set h1 = Sheets("Ingresar")
    For i = 3 To h1.Range("E" & Rows.Count).End(xlUp).Row
        Call Agregar_Fec(ComboBox1, h1.Cells(i, "E").Value)
        Call Agregar_Fec(ComboBox2, h1.Cells(i, "E").Value)
        Call Agregar(ComboBox3, h1.Cells(i, "A").Value)
    Next
End Sub
Sub Agregar_Fec(combo As ComboBox, dato As String)
    Dim fec1 As Date
    Dim fec2 As Date
    For i = 0 To combo.ListCount - 1
        fec1 = CDate(combo.List(i))
        fec2 = CDate(dato)
        If fec1 = fec2 Then Exit Sub
        If fec1 > fec2 Then combo.AddItem dato, i: Exit Sub
    Next
    combo.AddItem dato 'Es mayor lo agrega al final
End Sub
Sub Agregar(combo As ComboBox, dato As String)
    For i = 0 To combo.ListCount - 1
        Select Case StrComp(combo.List(i), dato, vbTextCompare)
            Case 0: Exit Sub 'ya existe en el combo y ya no lo agrega
            Case 1: combo.AddItem dato, i: Exit Sub 'Es menor, lo agrega antes del comparado
        End Select
    Next
    combo.AddItem dato 'Es mayor lo agrega al final
End Sub
'
Private Sub TXTATRAS_Click()
    Unload Me
End Sub
'

En otra oportunidad te anexo el código para guardar en la hoja los cambios.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas