PDA

Click to See Complete Forum and Search --> : [RESOLVED] Search and delete issues


swoozie
Jan 22nd, 2004, 12:48 PM
Okay, now I have a good one.

I need to do the following

run through a spreadsheet looking for an instance of criteria, i.e.,

Name Place This criteria can be part of a larger value in the same cell i.e., Name Place Day Month zip, etc....

Then after it is found I need to delete all rows below it until I reach a cell that is formated BOLD. then I need to stop the delete process and do the search process again.

__________________
Swoozie

Yesuslave
Jan 22nd, 2004, 02:54 PM
Hey there,

OK, this should get you started.



Sub DeleteLinesWacky()
'
Dim blnFound As Boolean
Dim strText As String 'This is the text you are looking for
Dim intLastRow As Integer 'This keeps a record of the last row you found your bold text in
Dim intFoundRow As Integer 'This is the row under the row you find your string
'
strText = "Josh"
'
intLastRow = 1
blnFound = True
Do Until blnFound = False
On Error Resume Next
Range(intLastRow & ":65536").Find(What:=strText).Activate
If blnFound = True Then

ActiveCell.Offset(1, 0).Select
intFoundRow = ActiveCell.Row
Do Until ActiveCell.Font.Bold = True Or ActiveCell.Row = 65536
ActiveCell.Offset(1, 0).Select
Loop
If ActiveCell.Row = 65536 Then Exit Sub
intLastRow = ActiveCell.Row - 1
If intFoundRow < intLastRow Then
Range(intFoundRow & ":" & intLastRow).Select
Selection.Delete
End If
Range("A" & intFoundRow).Select
intLastRow = ActiveCell.Row
End If
Loop



End Sub