A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

search for a string



 
 
Thread Tools Display Modes
  #1  
Old April 23rd, 2010, 02:24 AM posted to microsoft.public.excel.newusers
santana
external usenet poster
 
Posts: 6
Default search for a string

How can I search for a string (“Draft Documents”) in sheet1 and then delete
all the rows above the row containing the string and then delete the last two
rows in sheet1? Thank you
  #2  
Old April 23rd, 2010, 03:47 AM posted to microsoft.public.excel.newusers
ozgrid.com
external usenet poster
 
Posts: 328
Default search for a string

Try;

Sub DoIt()
Dim rRange As Range

On Error Resume Next
Set rRange = Range(Cells(1, 1). _
Cells.Find("Draft Documents", _
Cells(1, 1), xlFormulas, _
xlWhole, xlByRows, xlNext, False))
On Error GoTo 0

If Not rRange Is Nothing Then
rRange.EntireRow.Delete
Else
MsgBox "'Draft Documents' Not found"
End If

Set rRange = Cells.Find("*", _
Cells(1, 1), xlFormulas, _
xlPart, xlByRows, xlPrevious, False)

rRange.Offset(-2, 0).Range("A1:A2").EntireRow.Delete
End Sub



--
Regards
Dave Hawley
www.ozgrid.com
"santana" wrote in message
...
How can I search for a string (“Draft Documents”) in sheet1 and then
delete
all the rows above the row containing the string and then delete the last
two
rows in sheet1? Thank you


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:00 AM.


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