+ Reply to Thread
Results 1 to 5 of 5

Delete Rows with Value greater than X

  1. #1
    Forum Contributor
    Join Date
    10-23-2003
    Posts
    141

    Delete Rows with Value greater than X

    Hi,

    Does anyone have any suggestions for a Macro that would:

    Delete all rows in Sheet 2 THAT HAS A VALUE IN COLUMN A with a value greater than CELL B2 in Sheet 1?

    Any help would be greatly appreciated!
    Last edited by STEVEB; 07-26-2005 at 11:01 AM.

  2. #2
    Tom Ogilvy
    Guest

    Re: Delete Rows with Value greater than X

    Dim i as Long, rw as Long, rng as Range
    Dim crit as Double
    crit = worksheets("Sheet1").Range("B2").Value
    With worksheets("Sheet2")
    rw = .cells(rows.count,1).End(xlup).rw
    for i = rw to 1 step -1
    if .cells(i,1).Value > crit then
    if rng is nothing then
    set rng = .cells(i,1)
    else
    set rng = union(rng,.cells(i,1))
    end if
    end if
    Next
    End With
    if not rng is nothing then
    rng.EntireRow.Delete
    End if

    Would be one way. Others would be to use an Autofilter or put a formula in
    a dummy column and use special cells.

    --
    Regards,
    Tom Ogilvy

    "STEVEB" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Hi,
    >
    > Does anyone have any suggestions for a Macro that would:
    >
    > Delete all rows in Sheet 2 THAT HAS A VALUE IN COLUMN A with a value
    > greater than CELL B2 in Sheet 1?
    >
    > Any help would be greatly appreciated!
    >
    >
    > --
    > STEVEB
    > ------------------------------------------------------------------------
    > STEVEB's Profile:

    http://www.excelforum.com/member.php...fo&userid=1872
    > View this thread: http://www.excelforum.com/showthread...hreadid=390199
    >




  3. #3
    Forum Contributor
    Join Date
    10-23-2003
    Posts
    141
    Hi Tom,

    I was having a little trouble with the forulma:

    The code has this error message:

    Run Time Error '438':
    Object doesn't support this property or method

    At this line:
    rw = .Cells(Rows.Count, 1).End(xlUp).rw

    Does it matter that I am using dates?

    Cell b2 in sheet 1 is 7/31/05
    & all the cells in column A - Sheet 2 are dates.

    Thanks for your help.

  4. #4
    Tom Ogilvy
    Guest

    Re: Delete Rows with Value greater than X

    Typo:
    the last rw should be row

    rw = .Cells(Rows.Count, 1).End(xlUp).row


    --
    Regards,
    Tom Ogilvy


    "STEVEB" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Hi Tom,
    >
    > I was having a little trouble with the forulma:
    >
    > The code has this error message:
    >
    > Run Time Error '438':
    > Object doesn't support this property or method
    >
    > At this line:
    > rw = .Cells(Rows.Count, 1).End(xlUp).rw
    >
    > Does it matter that I am using dates?
    >
    > Cell b2 in sheet 1 is 7/31/05
    > & all the cells in column A - Sheet 2 are dates.
    >
    > Thanks for your help.
    >
    >
    > --
    > STEVEB
    > ------------------------------------------------------------------------
    > STEVEB's Profile:

    http://www.excelforum.com/member.php...fo&userid=1872
    > View this thread: http://www.excelforum.com/showthread...hreadid=390199
    >




  5. #5
    Forum Contributor
    Join Date
    10-23-2003
    Posts
    141
    Thanks Tom!

    Everything worked great!

    I appreciate your help!

+ 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