Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default Looping Through Sheet

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Looping Through Sheet

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default Looping Through Sheet

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 595
Default Looping Through Sheet

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Not Looping Roger Excel Discussion (Misc queries) 0 February 26th 08 05:18 PM
Looping through Sheet scott Excel Programming 5 January 7th 05 05:03 PM
looping through selected sheet tabs Gary Adamson[_2_] Excel Programming 4 December 7th 04 01:09 PM
Looping scottwilsonx[_54_] Excel Programming 0 October 5th 04 04:29 PM
looping to End Nabeel Moeen Excel Programming 2 February 25th 04 10:52 AM


All times are GMT +1. The time now is 12:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"