AllExperts > VB Script 
Search      
VB Script
Volunteer
Answers to thousands of questions
 Home · More VB Script Questions · Answer Library  · Encyclopedia ·
More VB Script Answers
Question Library

Ask a question about VB Script
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About David Barrett
Expertise
I can answer pretty much any question regarding VBScript, including WMI queries and advanced topics.

Experience
Many years programming, write script frequently for network management and to automate administrative tasks.

Education/Credentials
MCP

 
   

You are here:  Experts > Computing/Technology > Basic > VB Script > Excel VB script

VB Script - Excel VB script


Expert: David Barrett - 8/27/2008

Question
I would like to move to each row with the word "Total" in it and delete the row and repeat until every row with the word "Total" is deleted.

Answer
Example of this:

Sub DeleteTotal()
  Dim rngTotal As Range
  Set rngTotal = Cells.Find(What:="Total", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
      :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
      False, SearchFormat:=False)
  While Not rngTotal Is Nothing
     Rows(rngTotal.Row).Delete
     Set rngTotal = Cells.Find(What:="Total", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
         :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
         False, SearchFormat:=False)
  Wend
End Sub



The subroutine above will keep searching for the word "Total" (not case sensitive) and delete the row until no more occurrences of the word are found.  Note that it currently works on the active worksheet, but can easily be adapted to work on specific sheets as needed.

Add to this Answer   Ask a Question


 
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.