Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / November 2007

Tip: Looking for answers? Try searching our database.

delete rows when finding certain content.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
me - 24 Nov 2007 03:46 GMT
In a data containing worksheet, in column "A"
I would like to write a macro which finds the cell with content
"text2delete" and delete all the rows below including this "text2delete" row.

Something like below. Any help will be appreciated greatly. Thanks

Sub content_del()
   $A = Find "text2delete" entered value at A1 column
   then

   Range(A$:A65000").Select
   Selection.EntireRow.Delete
End Sub

or if it is easier this way,

delete all the rows A column value as "text2delete"

I guess this code should work for me.

Any help is greatly appreciated. Thanks..
sebastienm - 24 Nov 2007 05:09 GMT
Hi,
try something like:

  dim rg as range
  ''' find the cell
  set rg= activesheet.range("a:a").Find
(what:=<your_text>,lookin:=xlValues,...)
  ''' delete the rows bellow including rg
  if not rg is nothing then
     set rg=range(rg,rg.parent.cells(65536,1))
     rg.entirerow.delete
  end if
Signature

Regards,
Sébastien
<http://www.ondemandanalysis.com>

> In a data containing worksheet, in column "A"
> I would like to write a macro which finds the cell with content
[quoted text clipped - 17 lines]
>
> Any help is greatly appreciated. Thanks..
Per Jessen - 24 Nov 2007 05:16 GMT
> In a data containing worksheet, in column "A"
> I would like to write a macro which finds the cell with content
[quoted text clipped - 17 lines]
>
> Any help is greatly appreciated. Thanks..

Try this:

Sub DeleteText()
LookFor = "text2delete"

Range("A1").EntireColumn.Select
Selection.Find(What:=LookFor, After:=ActiveCell, LookIn:=xlFormulas _
       , LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, _
       MatchCase:=False).Select

Regards,

Per

FirstCell = Selection.Address
LastCell = Range(FirstCell).End(xlDown).Address
Range(FirstCell, LastCell).Delete

End Sub
thefirstcybot - 24 Nov 2007 10:58 GMT
Try going to www.learningiseasy.co.uk and look at the marco page and you will
find a marco to do this and maybe some more stuff.  I started creating this
website but due to the lack of visitors I have not updated it for ages.  

Hope this helps

> In a data containing worksheet, in column "A"
> I would like to write a macro which finds the cell with content
[quoted text clipped - 17 lines]
>
> Any help is greatly appreciated. Thanks..
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.