Hi Everyone
i have an code where the it adds the seq number according to blank row number and it works fine however if i delete any selected rows from the listbox then all of the below sequence numbers becomes and invalid and shows as attached image #REF!
below it is the code to Add the sequence numbers which works perfect
below it is code to delete the selected row, whereby when i delete a row i get an error on the next row.
i have an code where the it adds the seq number according to blank row number and it works fine however if i delete any selected rows from the listbox then all of the below sequence numbers becomes and invalid and shows as attached image #REF!
below it is the code to Add the sequence numbers which works perfect
VBA Code:
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Full")
Dim Last_Row As Long
Last_Row = Application.WorksheetFunction.CountA(sh.Range("A:A"))
sh.Range("A" & Last_Row + 2).Value = "=IF(B" & Last_Row + 1 & "="""","""",ROW()-2)"
below it is code to delete the selected row, whereby when i delete a row i get an error on the next row.
VBA Code:
Private Sub CommandButton3_Click()
If Me.ListBox1.ListIndex < 0 Then
MsgBox "Please select a record to update", vbCritical
Exit Sub
End If
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Full")
Dim Selected_Row As Long
Selected_Row = Application.WorksheetFunction.Match(Me.ListBox1.List(Me.ListBox1.ListIndex, 0), sh.Range("A:A"), 0)
sh.Range("A" & Selected_Row).EntireRow.Delete
End Sub