Why is code unexpectedly stopping?

goldenvision

Board Regular
Joined
Jan 13, 2004
Messages
234
I am running the code below to select a record in a list box on a userform then search through records until a match is found and mark the matched record with an "x". However the code seems to be stopping part way through and I can't figure out why. Any help would be greatly appreciated. (Code marked with comments below)

Code:
Private Sub lst_DeleteLeaveRequest_Click()
Dim i As Long, x
Dim leaveID As Integer
Dim rowCount As Integer
rowCount = 1

With Me.lst_DeleteLeaveRequest
    For i = 0 To .ListCount - 1
        If .Selected(i) Then
             leaveID = .List(i, 0)
MsgBox leaveID
        End If
    Next
End With
'++++THIS IS THE POINT WHERE THE CODE STOPS++++
Do Until Cells(rowCount, 1) = ""
If Cells(rowCount, 1).Value = leaveID Then
Cells(rowCount, 6).Value = "x"
Else
End If

rowCount = rowCount + 1
Loop
End Sub
 

Some videos you may like

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Alteran

Board Regular
Joined
Nov 25, 2009
Messages
117
Are their blank fields where you are running the code? as Excel will stop counting the second it comes to a blank cell.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,535
Messages
5,602,217
Members
414,513
Latest member
junbuggle

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top