Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
My Below Sub accepts a string, finds it and deletes the row in which the
string is found. Can someone help me modify it to continue searching through all cells that contain data and delete any other rows where the string occurs? USAGE: DeleteRowswString("myword") CODE Sub DeleteRowwString(ByVal sString As String) Dim theRange As Range, nCells As Integer, I As Integer Set theRange = Selection nCells = theRange.Cells.Count For I = nCells To 1 Step -1 If theRange.Cells(I).Value = sString Then theRange.Cells(I).EntireRow.Delete End If Next End Sub |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sub DeleteRowwString(ByVal sString As String)
Dim theRange As Range, nCells As Integer, I As Integer Set theRange = Intersect(Activesheet.UsedRange.Entirerow, _ Activesheet.Columns(1)).Cells nCells = theRange.Rows(theRange.rows.count).Row For I = nCells To 1 Step -1 If Application.countif(Cells(i,1).EntireRow,"*" & sString _ & "*") 0 then Cells(i,1).EntireRow.Delete End If Next End Sub -- Regards, Tom Ogilvy "scott" wrote in message .. . My Below Sub accepts a string, finds it and deletes the row in which the string is found. Can someone help me modify it to continue searching through all cells that contain data and delete any other rows where the string occurs? USAGE: DeleteRowswString("myword") CODE Sub DeleteRowwString(ByVal sString As String) Dim theRange As Range, nCells As Integer, I As Integer Set theRange = Selection nCells = theRange.Cells.Count For I = nCells To 1 Step -1 If theRange.Cells(I).Value = sString Then theRange.Cells(I).EntireRow.Delete End If Next End Sub |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
thanks guys, i'm a database programmer that's trying to learn spreedsheet
syntax. "Tom Ogilvy" wrote in message ... Sub DeleteRowwString(ByVal sString As String) Dim theRange As Range, nCells As Integer, I As Integer Set theRange = Intersect(Activesheet.UsedRange.Entirerow, _ Activesheet.Columns(1)).Cells nCells = theRange.Rows(theRange.rows.count).Row For I = nCells To 1 Step -1 If Application.countif(Cells(i,1).EntireRow,"*" & sString _ & "*") 0 then Cells(i,1).EntireRow.Delete End If Next End Sub -- Regards, Tom Ogilvy "scott" wrote in message .. . My Below Sub accepts a string, finds it and deletes the row in which the string is found. Can someone help me modify it to continue searching through all cells that contain data and delete any other rows where the string occurs? USAGE: DeleteRowswString("myword") CODE Sub DeleteRowwString(ByVal sString As String) Dim theRange As Range, nCells As Integer, I As Integer Set theRange = Selection nCells = theRange.Cells.Count For I = nCells To 1 Step -1 If theRange.Cells(I).Value = sString Then theRange.Cells(I).EntireRow.Delete End If Next End Sub |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Scott
You might find using the Find method to be faster than looping through all the cells. Try this Sub DeleteRowwString(ByVal sString As String) Dim rFound As Range Dim rLook As Range If TypeName(Selection) = "Range" Then Set rLook = Selection Set rFound = rLook.Find(sString, , xlValues, xlWhole) If Not rFound Is Nothing Then Do rFound.EntireRow.Delete Set rFound = rLook.FindNext Loop Until rFound Is Nothing End If End If End Sub -- Dick Kusleika Excel MVP Daily Dose of Excel www.dicks-blog.com scott wrote: My Below Sub accepts a string, finds it and deletes the row in which the string is found. Can someone help me modify it to continue searching through all cells that contain data and delete any other rows where the string occurs? USAGE: DeleteRowswString("myword") CODE Sub DeleteRowwString(ByVal sString As String) Dim theRange As Range, nCells As Integer, I As Integer Set theRange = Selection nCells = theRange.Cells.Count For I = nCells To 1 Step -1 If theRange.Cells(I).Value = sString Then theRange.Cells(I).EntireRow.Delete End If Next End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Not Looping | Excel Discussion (Misc queries) | |||
Looping through Sheet | Excel Programming | |||
looping through selected sheet tabs | Excel Programming | |||
Looping | Excel Programming | |||
looping to End | Excel Programming |