Autoajustar tablas al borrar registro

Para Dante Amor

Mira, lo que necesito es que al borrar un elemento de la tabla, esta se autoajuste sola para que no me genere espacios en blanco.

Y en esta que se borre el contenido y se autoajuste

El código que tengo es:

Public valor
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim c, h, b, u
    If Target.Count > 1 Then Exit Sub
    If Target.Row = 1 Then Exit Sub
    If Not Intersect(Target, Range("B:B")) Is Nothing Then
        For Each c In Target
            Set h = Sheets("CARACTERISTICAS DEL PROYECTO")
            If c = "" And valor <> "" Then
                Set b = h.Columns("N").Find(valor, lookat:=xlWhole)
                If Not b Is Nothing Then
                    b.Value = ""
                End If
            Else
                Set b = h.Columns("N").Find(c.Value, lookat:=xlWhole)
                If b Is Nothing Then
                    u = h.Range("N" & Rows.Count).End(xlUp).Row + 1
                    h.Cells(u, "N") = c.Value
                End If
            End If
        Next
    End If
End Sub
'
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    If Target.Row = 1 Then Exit Sub
    If Not Intersect(Target, Range("B:B")) Is Nothing Then
        If Target.Value <> "" Then
            valor = Target.Value
        End If
    End If
End Sub

1 Respuesta

Respuesta
1

H o l a:

En un correo nuevo me envías el archivo y una explicación de lo que necesitas. Recuerda poner tu nombre de usuario en el asunto.

Ya te envié el archivo :)

Te anexo el código del formulario para borrar en ambas hojas.

Private Sub CommandButton1_Click()
'Por.Dante Amor
    If ComboBox1 = "" Then
        MsgBox "Selecciona una torre"
        Exit Sub
    End If
    If ComboBox1.ListIndex = -1 Then
        ComboBox1 = ""
        MsgBox "Selecciona una torre válida"
        ComboBox1.SetFocus
        Exit Sub
    End If
    '
    Set h = Sheets("BD")
    Set h2 = Sheets("CARACTERISTICAS DEL PROYECTO")
    f = ComboBox1.ListIndex + 2
    h.Cells(f, "B").ListObject.ListRows(f - 1).Delete
    '
    Set b = h2.Columns("N").Find(ComboBox1, lookat:=xlWhole)
    If Not b Is Nothing Then
        f = b.Row
        h2.Cells(f, "N").ListObject.ListRows(f - 5).Delete
    End If
    ComboBox1 = ""
    Call CargarCombo
    MsgBox "Torre eliminada"
End Sub
'
Private Sub CommandButton2_Click()
    Unload Me
End Sub
'
Private Sub UserForm_Activate()
'Por.Dante Amor
    Call CargarCombo
End Sub
'
Sub CargarCombo()
    ComboBox1.Clear
    Set h = Sheets("BD")
    For i = 2 To h.Range("B" & Rows.Count).End(xlUp).Row
        ComboBox1.AddItem (h.Cells(i, "B"))
    Next
End Sub

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas