By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,636 Members | 1,693 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,636 IT Pros & Developers. It's quick & easy.

Delete method of Range class failed - HELP!

P: n/a
Hi

Any help on this would be appreciated cos its driving me insane.

I have a function in VB.NET that takes in an excel range and tries to
delete rows where the first column starts with a string. Only it
doesnt work and all i get is "Delete method of Range class failed"
whatever i do.

Any suggestions?

Public Function DeleteRowsContaining(ByVal objRange As
Excel.Range, ByVal strDeleteString As String) As Excel.Range

Dim lngRow As Long
Dim strCellValue As String

For lngRow = objRange.Rows.Count To 1 Step -1
strCellValue = objRange.Cells(lngRow, 1).Value
If strCellValue.StartsWith(strDeleteString) = True Then
objRange.Rows(lngRow).EntireRow.Delete()
End If
Next lngRow

Return objRange

End Function

Many thanks in advance

R
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
You might have to delcare the worksheet as the active sheet before using the
delete range.

"richilli" wrote:
Hi

Any help on this would be appreciated cos its driving me insane.

I have a function in VB.NET that takes in an excel range and tries to
delete rows where the first column starts with a string. Only it
doesnt work and all i get is "Delete method of Range class failed"
whatever i do.

Any suggestions?

Public Function DeleteRowsContaining(ByVal objRange As
Excel.Range, ByVal strDeleteString As String) As Excel.Range

Dim lngRow As Long
Dim strCellValue As String

For lngRow = objRange.Rows.Count To 1 Step -1
strCellValue = objRange.Cells(lngRow, 1).Value
If strCellValue.StartsWith(strDeleteString) = True Then
objRange.Rows(lngRow).EntireRow.Delete()
End If
Next lngRow

Return objRange

End Function

Many thanks in advance

R

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.