473,396 Members | 1,780 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Delete method of Range class failed - HELP!

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
1 6236
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: lawrence | last post by:
I've two scripts, one to upload images, another to delete them. The upload script works fine, but the delete script has permissions trouble. How can PHP not have permission to delete an image it...
11
by: Jason Heyes | last post by:
I would like to be able to extract an integer from a stream without having to write a test when I want the integer within some range. Unfortunately there is no range-checked integer type in the...
3
by: Uwe Range | last post by:
Hi to all, I am displaying a list of records in a subform which is embedded in a popup main form (in order to ensure that users close the form when leaving it). It seems to be impossible to...
3
by: Ryan Liu | last post by:
Hi there, I got a NullReferenceException when delete last row in a datagrid. I had hard time to solve since it does not occur in my own code. I put a datagrid in my inherited user control,...
6
by: Karl Richards | last post by:
I am attempting to delete duplicate rows in a spreadsheet using the Excel object. Does anyone have any idea how to do this? I've looked everywhere that I can find on the Web and have not been...
11
by: comp.lang.php | last post by:
Once again, I thought my class method deleteZip() would do the trick, but it never deletes any .zip* file found in a directory: /** * Delete any latent ZIP files found in this album. This...
4
by: ielamrani | last post by:
Hi, I am getting this error when I try to export to an excel sheet. When I click on a button to export the first time it's fine, I rename the exported excel sheet and I try to export it again and I...
7
by: MrHuggykins | last post by:
First Class------------------ // Car class to define all the methods/classes in CarUser public class Car { // Creates object Car public Car() { } // Let's a car have initial gas in the tank
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.