abdelfattah
Well-known Member
- Joined
- May 3, 2019
- Messages
- 1,507
- Office Version
- 2019
- 2010
- Platform
- Windows
H ello
I try deleting from sheet by selected row in listbox except the last row based on selected sheet from combobox , but doesn't happens anything !
here is the code
I hope somebody has idea .
I try deleting from sheet by selected row in listbox except the last row based on selected sheet from combobox , but doesn't happens anything !
here is the code
VBA Code:
Private Sub CommandButton2_Click()
With Me.ListBox1
If .ListIndex = .ListCount - 1 Then
MsgBox "you have not permission to do that", vbExclamation
Exit Sub
End If
End With
Dim i As Integer
Application.ScreenUpdating = False
Set ws = Sheets(ComboBox1.Value)
If MsgBox("Are you sure you want to delete this data row?", vbYesNo + vbQuestion, "Delete Row?") = vbYes Then
With ws
For i = .Range("A" & Rows.Count).End(xlUp).Row To 1 Step -1
If .Cells(i, 1) = ListBox1.List(ListBox1.ListIndex) Then
.Rows(i).Delete
End If
Next i
End With
End If
Application.ScreenUpdating = True
End Sub