EXCEL macro : Search words and deleting row above words

For this post  I will show how to search for words and deleting row above the words. In this example, I will write some code to find words in sheet4 and deleting row above the cell if the words are found.

=====================================================
 Sub deleterow()  
  Sheet4.Activate 'activate sheet4  
  Sheet4.Columns("A:A").Select 'select range for column A  
 'this below command will search the word "my name " in columnA  
  Selection.Find(What:="my name", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _  
  xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False).Activate  
  ActiveCell.Select  
  'this command will set the range 1 cell above the word "my name " if found till cell A1  
  Range(ActiveCell.Offset(-1, 0), "A1").Select  
 'this command will delete the selected range  
 Selection.Delete (xlUp)  
 end sub()  
=====================================================

No comments:

Post a Comment