LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default rewriting macro to only clear contents


I have the following macro that I need to modify so that instead of
deleting the whole row, it only clears the data, but still moves those
rows containing "N" in column E remain, and are moved up to the top
lines (row 3 for me), without deleting the format that I have for cells
A1:E50, and clearing all with a "Y" in column E. Does that make sense?
I'd also like to add an "are you sure you want to delete anything that
has yet to clear?" prompt prior to execution. See below and tia.....

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("Spending")
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


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

 
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
Macro to clear contents of certain cells MrAcquire Excel Discussion (Misc queries) 3 February 11th 10 05:25 PM
Macro to clear contents and put an X bevchapman Excel Discussion (Misc queries) 3 March 17th 09 07:03 PM
Clear contents macro Dave Excel Programming 10 April 6th 06 07:41 PM
Need macro to clear contents steve_sr2[_2_] Excel Programming 4 February 28th 06 09:20 AM
Clear Contents Macro SJC Excel Worksheet Functions 3 October 27th 05 07:26 PM


All times are GMT +1. The time now is 03:43 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"