Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2006

Tip: Looking for answers? Try searching our database.

Delete a range of rows ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
SpookiePower - 24 Jan 2006 14:42 GMT
I made this code to delete a range of rows, but I found out
that this code only delete every second row.

Do Until Worksheets("Materielplacering").Cells(lCurrentRow, 4).Value = ""
       Worksheets("Materielplacering").Rows(lCurrentRow).Delete
        lCurrentRow = lCurrentRow + 1
Loop

I need to delete some rows, starting from row X to Y
It must be possible to make it like Range.(X,Y).delete
or something like that, but I'm not sure how to write
this single line of code.

Signature

Mit fotoalbum
www.photo.activewebsite.dk

Tom Ogilvy - 24 Jan 2006 14:58 GMT
Do Until Worksheets("Materielplacering").Cells(lCurrentRow, 4).Value = ""
       Worksheets("Materielplacering").Rows(lCurrentRow).Delete
Loop

as you delete, the next row will become the current row, so you don't need
to increment lCurrentRow

Signature

Regards,
Tom Ogilvy

> I made this code to delete a range of rows, but I found out
> that this code only delete every second row.
[quoted text clipped - 8 lines]
> or something like that, but I'm not sure how to write
> this single line of code.
SpookiePower - 24 Jan 2006 15:07 GMT
So simple :) Thanks.

But what if I want to delete a range of rows from X to Y. How do I
write the "Range-Delete" line ?
Bob Phillips - 24 Jan 2006 15:16 GMT
   With Worksheets("Materielplacering")
       For i = Y To X Step -1
           If .Cells(i, 4).Value = "" Then
               .Rows(i).Delete
           End If
       Next i
   End With

--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

> So simple :) Thanks.
>
> But what if I want to delete a range of rows from X to Y. How do I
> write the "Range-Delete" line ?
SpookiePower - 24 Jan 2006 15:23 GMT
Tom Ogilvy - 24 Jan 2006 15:19 GMT
X = 10
Y = 30

lCurrentRow = X
With Worksheets("Materielplacering")
 .Cells(lCurrentRow, 1).Resize(Y-X+1,1).EntireRow.Delete
End With

Signature

Regards,
Tom Ogilvy

> So simple :) Thanks.
>
> But what if I want to delete a range of rows from X to Y. How do I
> write the "Range-Delete" line ?
SpookiePower - 24 Jan 2006 15:24 GMT
Thanks. I'll take a look at it later to day.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.