RE: Decrementing row after deletion

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



You might want to exit your second loop when you delete the row.


--
Regards,
Tom Ogilvy


"SueCool" wrote:

Thanks Mike - you are a star, but that was a bit of an easy one!

Sue
--
I''''m not a complete idiot - there are some parts missing!


"Mike H" wrote:

Sue,

Put another for/next loop in

Cells(x, 1).Select
for y = 1 to 256
MyPos = InStr(1, Cells(x, y).Value, strWhat, 1)
If MyPos > 0 Then
Response = MsgBox("Delete?", vbYesNo + vbQuestion)
If Response = vbYes Then
Selection.EntireRow.Delete
next y


Not tested but sjould work,

Mike
"SueCool" wrote:

Thanks Mike - that's done the job. Luckily the strings I am searching for
are in the first column, but how would I search all the cells in each row?

Sue
--
I''''m not a complete idiot - there are some parts missing!


"Mike H" wrote:

Do it in reverse to cure the problem

Sub deleteit()
lastrowcola = Range("A65536").End(xlUp).Row '<Alter to suit
For x = lastrowcola To 1 Step -1
Cells(x, 1).Select
MyPos = InStr(1, Cells(x, 1).Value, strWhat, 1)
If MyPos > 0 Then
Response = MsgBox("Delete?", vbYesNo + vbQuestion)
If Response = vbYes Then
Selection.EntireRow.Delete
End If
End If
Next

End Sub

Mike


"SueCool" wrote:

I use the following code to delete a row containing a particular string, but
if two succesive rows contain the string, the second row is skipped. How can
I decrement the row counter, so that after a deletion the next for loop works
on the same row?

For Each C In myRange
C.Select
MyPos = InStr(1, C.Value, strWhat, 1)
If MyPos > 0 Then
Response = MsgBox("Delete?", vbYesNo + vbQuestion)
If Response = vbYes Then
Selection.EntireRow.Delete
End If
End If
Next

Any help would be much appreciated,

Sue

--
I''m not a complete idiot - there are some parts missing!
.



Relevant Pages

  • RE: Decrementing row after deletion
    ... Thanks Mike - you are a star, but that was a bit of an easy one! ... I''''m not a complete idiot - there are some parts missing! ... If MyPos> 0 Then ...
    (microsoft.public.excel.programming)
  • Re: working with 8 and 16 bit regions of mem
    ... >> Am I wrong in assuming that this loop will never run? ... I am feeling like an idiot, ... >> If you initialize ...
    (comp.lang.c)
  • dependency hell
    ... I can't install or uninstall any major packages anymore, or I spend an hour going in a loop trying to figure out ... dependencies. ... i tend to ignore the following kinds of replies: top-bottom-middle posting, grammar, spelling, read the manual you idiot, search google you idiot... ...
    (alt.os.linux.suse)
  • Re: Need some help...
    ... you have written yourself and saying, 'What idiot wrote this rubish?'. ... And nothing more sobering than doing it 5 minutes after you post a EUREKA! ... error stating that I'm passing too many variables. ... For...Next loop, but the actual line stating i_Compress.CompressFolder... ...
    (microsoft.public.dotnet.languages.vb)
  • Re: urgent! bug in Brett Shoelsons freehanddraw().
    ... >i am an idiot. ... > the problen was using uint8! ... Still...you might want to avoid reassigning xy values in a loop in the first ...
    (comp.soft-sys.matlab)