+ Reply to Thread
Results 1 to 7 of 7

Delete a range of rows ?

  1. #1
    SpookiePower
    Guest

    Delete a range of rows ?


    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.






    --
    Mit fotoalbum
    www.photo.activewebsite.dk



  2. #2
    Tom Ogilvy
    Guest

    Re: Delete a range of rows ?

    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

    --
    Regards,
    Tom Ogilvy

    "SpookiePower" <[email protected]> wrote in message
    news:[email protected]...
    >
    > 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.
    >
    >
    >
    >
    >
    >
    > --
    > Mit fotoalbum
    > www.photo.activewebsite.dk
    >
    >




  3. #3
    SpookiePower
    Guest

    Re: Delete a range of rows ?

    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 ?


  4. #4
    Bob Phillips
    Guest

    Re: Delete a range of rows ?


    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)

    "SpookiePower" <[email protected]> wrote in message
    news:[email protected]...
    > 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 ?
    >




  5. #5
    Tom Ogilvy
    Guest

    Re: Delete a range of rows ?

    X = 10
    Y = 30

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

    --
    Regards,
    Tom Ogilvy


    "SpookiePower" <[email protected]> wrote in message
    news:[email protected]...
    > 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 ?
    >




  6. #6
    SpookiePower
    Guest

    Re: Delete a range of rows ?

    Thanks.


  7. #7
    SpookiePower
    Guest

    Re: Delete a range of rows ?

    Thanks. I'll take a look at it later to day.


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1