Sooo, i had a nice little subroutine that would remove all but a single row in a table.
Sub ClearFormTableRows(sourceRange, countRange)
Dim rowsCount As Integer, rowRangeName As Object
rowsCount = Application.WorksheetFunction.CountA(countRange)
With sourceRange
Do Until rowsCount = 1
.ListObject.ListRows(2).Delete
rowsCount = rowsCount - 1
If rowsCount = 1 Then Exit Do
Loop
End With
End Sub
And until today it worked. But in the main routine that calls it i added another call, same syntax just for a different table and now it wont do anything, throws an error 9 subroutine out of range.
The row it highlights is this one: .ListObject.ListRows(2).Delete
But, if i comment out either of the calls, it doesn’t matter which, it will execute properly on that table. But ask it to do both and it wont do either.
What am i doing wrong?
Try in this way: I removed
rowRangeName objectas it’s not in use for given snippet in your question.Reference:
PS: Might not be related, but please declare parameters explicitly with either
ByReforByVal:Sub ClearFormTableRows(ByRef sourceRange As Range, ByRef countRange As Range)🙂