Delete Method Of Range Class Failed Error

Joined
Aug 10, 2010
Messages
2
Reaction score
0
I am using VB language behind excel to code. When I hit delete button on excel sheet, I get following error.

DELETE METHOD OF RANGE CLASS FAILED ERROR, when fol
lowing line encounters: ActiveSheet.Rows(Rnum).EntireRow.DELETE

My code:


Public KintanaNo As String
Public serno As Integer
Public Rnum As Integer
Public totalrows As Integer

Private Sub btndelete_Click()
Dim i As Integer
KintanaNo = Trim(txtkintana.Text)
serno = Trim(txtserial.Text)
totalrows = ActiveSheet.UsedRange.Rows.Count
Rnum = 1

For i = 1 To totalrows Step 1
If (ActiveSheet.Cells(Rnum, 1).Value) = serno And (ActiveSheet.Cells(Rnum, 2).Value) = KintanaNo Then
ActiveSheet.Rows(Rnum).EntireRow.DELETE
End If
Rnum = Rnum + 1
Next i



Can anyone please tell what is alternative method to avoid this error?
 
Joined
Aug 10, 2010
Messages
2
Reaction score
0
I got the solution.

The sheet should be unprotected at the start of the code .

ActiveSheet.Unprotect Password:="Wiccvv"


At the end of the code, again protect the sheet like this:-

ActiveSheet.protect Password:="Wiccvv"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top