Complemento a:¿Cómo modificar valor en un campo(columna) de una hoja excel, desde un ListBox VBA?

Que me dio una gran solución, he podido continuar con mi proyecto, pero me quedó dando vuelta una nueva consulta sobre lo mismo.

¿Cómo puedo hacer para que no se ejecute nada, mientras no seleccione algún registro en el LISTBOX? En lo posible con algún mensaje en pantalla que me diga por ejemplo "DEBE SELECCIONAR UN REGISTRO" y/o "REGISTRO GUARDADO CON ÉXITO"

<pre>Private Sub Btn_Cerrar_Click() End Sheets("INGRESO").Select End Sub Private Sub Btn_Devolver_Click() If ListBox1.Selected(x) = False Then Exit Sub '============> NO ME RESULTA AQUÍ ' MsgBox "DEBE SELECCIONAR UN REGISTRO"
For x = 1 To ListBox1.ListCount - 1 'Recorremos filas del Listbox If ListBox1.Selected(x) = True Then 'Si hay algún registro seleccionado en el ListBox With Sheets("INGRESO") .Cells(Repes(x), "J") = Date 'coloca fecha actual en fila y columna respectiva .Cells(Repes(x), "K") = "DEVUELTO" 'coloca el texto "DEVUELTO" en fila y columna respectiva End With Exit For End If Next x End Sub
Private Sub Cmbo_Nivel_Change() Dim NumRep As Integer NumRep = 1 ReDim Repes(1)
If Cmbo_Nivel.Text = "" Then Exit Sub ListBox1.ColumnCount = 7 'Permite definir cuantas columnas se mostrarán el el ListBox ListBox1.ColumnWidths = "80;110;100;50;220;30;60" 'Establecemos los anchos de las columnas del ListBox ListBox1.Clear 'Limpiamos el ListBox With Sheets("INGRESO") 'Con la hoja de nombre "INGRESO" activa 'Carga encabezado, pero no se cual es su utilidad ListBox1.AddItem .Cells(4, "A") 'Coloca el encabezado o título, si lo omito no llena lo demás y marca error ListBox1.List(ListBox1.ListCount - 1, 1) = .Cells(4, "C") ListBox1.List(ListBox1.ListCount - 1, 2) = .Cells(4, "D") ListBox1.List(ListBox1.ListCount - 1, 3) = .Cells(4, "E") ListBox1.List(ListBox1.ListCount - 1, 4) = .Cells(4, "F") For i = 2 To .Range("E" & .Rows.Count).End(xlUp).Row If .Cells(i, "E") = Cmbo_Nivel Then 'Si la columna E=ComboBox (si el valor es el mismo) ListBox1.AddItem .Cells(i, "A") 'Permite ir llenando el resto de los datos(punto de inicio o referencia) ListBox1.List(ListBox1.ListCount - 1, 1) = .Cells(i, "C") ListBox1.List(ListBox1.ListCount - 1, 2) = .Cells(i, "D") ListBox1.List(ListBox1.ListCount - 1, 3) = .Cells(i, "E") ListBox1.List(ListBox1.ListCount - 1, 4) = .Cells(i, "F") ListBox1.List(ListBox1.ListCount - 1, 5) = .Cells(i, "G") ListBox1.List(ListBox1.ListCount - 1, 6) = .Cells(i, "I") ListBox1.List(ListBox1.ListCount - 1, 7) = i 'Número de índice de la fila en que están los registros indice = i Repes(NumRep) = i NumRep = NumRep + 1 ReDim Preserve Repes(NumRep) End If Next End With End Sub
Private Sub Cmbo_Recuso_Change() With Sheets("INGRESO") 'Con la hoja de nombre "INGRESO" activa End With End Sub Private Sub UserForm_Initialize()
Sheets("INGRESO").Select For i = 2 To Range("E" & Rows.Count).End(xlUp).Row 'para llenar datos sin repetir AddItem Cmbo_Nivel, Cells(i, "E") 'llama a subrutina que recorre todos los elementos(Sub AddItem) Next
Sheets("INGRESO").Select End Sub
Sub AddItem(cmbBox As ComboBox, sItem As String) ' agrega los item únicos y en orden alfabético For i = 0 To cmbBox.ListCount - 1 Select Case StrComp(cmbBox.List(i), sItem, vbTextCompare) Case 0: Exit Sub 'ya existe en el combo y ya no lo agrega 'Si comparación es 1, es menor lo agrega antes del comparado Case 1 cmbBox.AddItem sItem, i Exit Sub End Select Next 'Si en la comparación es mayor lo agrega al final cmbBox.AddItem sItem End Sub</pre>

1 Respuesta

Respuesta
1

Ya te mande la solución en el e-mail que recibí tuyo, ahora he visto que habías mandado esta pregunta.

Mira a ver si era eso lo que necesitabas.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas