+ Reply to Thread
Results 1 to 2 of 2

Assign button to clear all, "except"

  1. #1
    Registered User
    Join Date
    12-28-2005
    Posts
    38

    Assign button to clear all, "except"

    I want to create a button that, when pressed will clear all rows that have "Y" in column E. How do I accomplish this? I know nothing about macros, so please keep that in mind when explaining. I really appreciate the help!

    -darkwood

  2. #2
    Jim Thomlinson
    Guest

    RE: Assign button to clear all, "except"

    Here is some code that should do what you want. You will need to change the
    line that says Sheet2 to the sheet you want to clean. The code assumes that
    your Y's and N's are in Cells E2 and below... You can change that if you
    need...

    Sub ClearData()
    Dim rngToDelete As Range
    Dim rngToSearch As Range
    Dim strFirstAddress As String
    Dim rngFound As Range
    Dim wks As Worksheet

    Set wks = Worksheets("Sheet1")
    With wks
    Set rngToSearch = .Range(.Range("E2"), _
    .Cells(Rows.Count, "E").End(xlUp))
    End With

    Set rngFound = rngToSearch.Find(What:="Y", _
    LookAt:=xlWhole, _
    MatchCase:=False)
    If rngFound Is Nothing Then
    MsgBox "Nothing to Delete"
    Else
    Set rngToDelete = rngFound
    strFirstAddress = rngFound.Address
    Do
    Set rngToDelete = Union(rngFound, rngToDelete)
    Set rngFound = rngToSearch.FindNext(rngFound)
    Loop Until rngFound.Address = strFirstAddress
    rngToDelete.EntireRow.Delete
    End If
    End Sub

    You did not mention how you wanted to call the procedure so I can not tell
    you the best place to put it...
    --
    HTH...

    Jim Thomlinson


    "darkwood" wrote:

    >
    > I want to create a button that, when pressed will clear all rows that
    > have "Y" in column E. How do I accomplish this? I know nothing about
    > macros, so please keep that in mind when explaining. I really
    > appreciate the help!
    >
    > -darkwood
    >
    >
    > --
    > darkwood
    > ------------------------------------------------------------------------
    > darkwood's Profile: http://www.excelforum.com/member.php...o&userid=29948
    > View this thread: http://www.excelforum.com/showthread...hreadid=512410
    >
    >


+ 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