G
Guest
Option2ListBox populates with the items contained in Col H of the 'Schedules'
tab; the user can then select 1 or more of these items. For each selected
item, I want Excel to go to the 'Schedules' tab and delete any row that has
that item in Col H. Problem is that the code is not consistently deleting
all the corresponding rows for those items selected in the listbox. This
must be something simple I'm overlooking. Can anyone help???? Also, is
there a quicker way to delete these rows? Am a little concerned about speed,
since there's likely to be several thousand rows to look through.
Private Sub OKButton_Click()
Dim i As Long, j As Long
Dim ws As Worksheet
Dim cells As Range
j = 0
For i = 0 To Me.Option2ListBox.ListCount - 1
If Me.Option2ListBox.Selected(i) = True Then
With worksheets("Schedules")
Set rngToSearch = .Range(.Range("H1"), .cells(Rows.Count,
"H").End(xlUp))
End With
For Each rng In rngToSearch
If rng = Me.Option2ListBox.List(i) Then
rng.EntireRow.Delete
End If
Next
j = j + 1
End If
Next i
Unload ImportingSchedules
End Sub
tab; the user can then select 1 or more of these items. For each selected
item, I want Excel to go to the 'Schedules' tab and delete any row that has
that item in Col H. Problem is that the code is not consistently deleting
all the corresponding rows for those items selected in the listbox. This
must be something simple I'm overlooking. Can anyone help???? Also, is
there a quicker way to delete these rows? Am a little concerned about speed,
since there's likely to be several thousand rows to look through.
Private Sub OKButton_Click()
Dim i As Long, j As Long
Dim ws As Worksheet
Dim cells As Range
j = 0
For i = 0 To Me.Option2ListBox.ListCount - 1
If Me.Option2ListBox.Selected(i) = True Then
With worksheets("Schedules")
Set rngToSearch = .Range(.Range("H1"), .cells(Rows.Count,
"H").End(xlUp))
End With
For Each rng In rngToSearch
If rng = Me.Option2ListBox.List(i) Then
rng.EntireRow.Delete
End If
Next
j = j + 1
End If
Next i
Unload ImportingSchedules
End Sub