Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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


--
darkwood
------------------------------------------------------------------------
darkwood's Profile: http://www.excelforum.com/member.php...o&userid=29948
View this thread: http://www.excelforum.com/showthread...hreadid=512410

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default 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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
HELP! Clicking "$" button changes format to ";;" not what it shoul Rock Robster Excel Discussion (Misc queries) 1 October 7th 06 04:04 AM
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next BCB New Users to Excel 7 May 13th 06 10:02 PM
Adding a "CLEAR" button to the worksheet Billy Excel Discussion (Misc queries) 1 January 8th 06 06:09 PM
commnd button - when i rt click, "assign macro" isnt an option... kevin[_3_] Excel Programming 1 November 12th 04 09:52 PM


All times are GMT +1. The time now is 07:47 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"