dss28
Board Regular
- Joined
- Sep 3, 2020
- Messages
- 165
- Office Version
- 2007
- Platform
- Windows
I have a userform in which I have refresh button to load the listbox with data from a worksheet.
A delete button to select a row for deletion etc.
The delete code was functioning for several months before but suddenly is stopping now at the "no row is selected" stage even after selecting the row in the listbox.
Need advice why it might be stopping now.
The code for row selection and delete command is below:
[/CODE]
A delete button to select a row for deletion etc.
The delete code was functioning for several months before but suddenly is stopping now at the "no row is selected" stage even after selecting the row in the listbox.
Need advice why it might be stopping now.
The code for row selection and delete command is below:
VBA Code:
[CODE=vba]Private Sub CommandButton5_Click() 'delete row
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.EnableEvents = False
ActiveSheet.DisplayPageBreaks = False
If Selected_List = 0 Then
MsgBox "No row is selected.", vbOKOnly + vbInformation, "Delete"
Exit Sub
End If
Dim i As VbMsgBoxResult
i = MsgBox("Do you want to delete the selected record?", vbYesNo + vbQuestion, "Delete")
If i = vbNo Then Exit Sub
Dim row As Long
row = Me.ListBox1.List(Me.ListBox1.ListIndex, 0) + 1
ThisWorkbook.Sheets("Data").Rows(row).Delete
MsgBox "Selected records has been deleted successfully.", vbOKOnly + vbInformation, "Delete"
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Application.EnableEvents = True
ActiveSheet.DisplayPageBreaks = True
End Sub
Function Selected_List() As Long
Dim i As Long
Selected_List = 0
If UserForm8.ListBox1.ListCount < 1 Then Exit Function
For i = 0 To UserForm8.ListBox1.ListCount - 1
If UserForm8.ListBox1.Selected(i) = True Then
Selected_List1 = i + 1
Exit For
End If
Next i
End Function