PC Review


Reply
Thread Tools Rate Thread

Delete method of Range class failed - HELP!

 
 
richilli
Guest
Posts: n/a
 
      21st Oct 2004
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
 
Reply With Quote
 
 
 
 
=?Utf-8?B?RGVubmlz?=
Guest
Posts: n/a
 
      22nd Oct 2004
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
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete Method Of Range Class Failed Error prasadnk2010 Microsoft Excel Programming 1 11th Aug 2010 04:47 AM
Delete method of Range class failed dan_coder Microsoft Excel Programming 1 24th Jul 2006 10:16 AM
"delete method of range class failed Kathy Goldie Microsoft Excel Programming 2 19th May 2005 06:45 PM
Delete method of Range class failed - HELP!!! richilli Microsoft Excel Programming 1 20th Oct 2004 06:24 PM
runtime error '1004' delete Method of Range Class Failed Jack Microsoft Excel Programming 3 14th Apr 2004 08:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:46 PM.