+ Reply to Thread
Results 1 to 3 of 3

Deleting lines with a variable.

  1. #1

    Deleting lines with a variable.

    Hello,

    In my macro I want to delete some lines depending on a test.
    I loop through some lines and do a check whether to delete the line.
    I've a linenumber stored in a variable i. The range object does not
    seem to accept my varaiable however. If I just enter the variable e.g.

    Worksheets(asset).Range(i).Delete
    or
    Worksheets(asset).Range(i:i).Delete

    Excel will not accept it. If I add quotes I get:

    Worksheets(asset).Range("i").Delete (which is not accepted)
    or
    Worksheets(asset).Range("i:i").Delete (which deletes a column instead
    of a row)

    So, how do I delete a line with a linenumber stored in a variable? If
    it's not allowed to use a variable in the rangeobject, what would be an
    efficient work around?

    Thanks in Advance
    Wilco


  2. #2
    Gary Keramidas
    Guest

    Re: Deleting lines with a variable.

    this would delete row 10 on sheet1

    Sub r()
    i = 10
    Worksheets("sheet1").Rows(i).EntireRow.Delete
    End Sub

    --


    Gary


    <[email protected]> wrote in message
    news:[email protected]...
    > Hello,
    >
    > In my macro I want to delete some lines depending on a test.
    > I loop through some lines and do a check whether to delete the line.
    > I've a linenumber stored in a variable i. The range object does not
    > seem to accept my varaiable however. If I just enter the variable e.g.
    >
    > Worksheets(asset).Range(i).Delete
    > or
    > Worksheets(asset).Range(i:i).Delete
    >
    > Excel will not accept it. If I add quotes I get:
    >
    > Worksheets(asset).Range("i").Delete (which is not accepted)
    > or
    > Worksheets(asset).Range("i:i").Delete (which deletes a column instead
    > of a row)
    >
    > So, how do I delete a line with a linenumber stored in a variable? If
    > it's not allowed to use a variable in the rangeobject, what would be an
    > efficient work around?
    >
    > Thanks in Advance
    > Wilco
    >




  3. #3

    Re: Deleting lines with a variable.

    Ok, Thanks a lot!


+ 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