Consulting

Results 1 to 3 of 3

Thread: Macro eliminates row and fix alignment

  1. #1
    VBAX Regular
    Joined
    Aug 2013
    Posts
    56
    Location

    Macro eliminates row and fix alignment

    Hi again,

    I have a database that receives data and nobody can change. To delete the data I use a macro where I write the number of the column ID and it deletes the row (can see the code below). And what I want it's when a row is removed, the ID numbers automatically readjust to always stay with the sequence 1,2,3,4,5,6,7,8... You can see this xlsx: lmb.xlsx Does anyone know how to do?


    Private Sub CommandButton1_Click()


    ThisWorkbook.Worksheets("Plan1").Activate


    Range("B7").Select
    While ActiveCell <> ""
    If TextBox1.Text = ActiveCell Then
    While ActiveCell = TextBox1.Text
    ActiveCell.EntireRow.Delete


    Wend
    End If
    ActiveCell.Offset(1, 0).Activate
    Wend


    End Sub
    Cheers!

  2. #2
    VBAX Regular
    Joined
    Nov 2011
    Location
    Ufa
    Posts
    75
    Location
    Hi Osevero,
    maybe
    Private Sub CommandButton1_Click()
    Dim r As Range
    With Sheets("Plan1")
        Set r = .Columns(2).Find(What:=TextBox1.Text, lookat:=xlWhole)
        If Not r Is Nothing Then
            r.EntireRow.Delete
            With .Range("B7", Cells(Rows.Count, 2).End(xlUp))
                .FormulaR1C1 = "=ROW(RC[-2])-6"
                .Value = .Value
            End With
        End If
    End With
    End Sub

  3. #3
    VBAX Regular
    Joined
    Aug 2013
    Posts
    56
    Location
    Thanks nilem!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •