Do Loop

  • Thread starter Thread starter jacqui
  • Start date Start date
J

jacqui

I've got myself in a bit of a muddle with a Do Loop in
that I've created a bit of an endless cycle. My code is
as follows, it worked fine until I added c.Offset(2,0),
previously it was just c.Resize(1) etc, and now the c.Row
<> firstrow is out of sync so it doesn't know when to stop
and ends up repeating the loop again. Can anyone help?
In fact Tom are you on-line this afternoon 'cause you
kindly helped me with this original code.
Many thanks
Jacqui

Set c = .Find("Other", LookIn:=xlValues, MatchCase:=False)
If Not c Is Nothing Then
firstrow = c.Row
i = 0
Do
i = i + 1
c.Offset(2, 0).Resize
(1).EntireRow.Insert
If i = 1 Then firstrow = firstrow + 1
Set c = .FindNext(c)
Loop While c.Row <> firstrow
End If
 
Sub Tester1()
Dim lastrow As Long
With Columns(5)
Set c = .Find("Other", .Cells(1, 1), _
LookIn:=xlValues, MatchCase:=False)
If Not c Is Nothing Then
Do
lastrow = c.Row
c.Offset(2, 0).Resize(1).EntireRow.Insert
If i = 1 Then firstrow = firstrow + 2
Set c = .FindNext(c)
Loop While c.Row > lastrow
End If
End With
End Sub

might be what you want.
 
Tom

Thank you

Jacqui
-----Original Message-----
Sub Tester1()
Dim lastrow As Long
With Columns(5)
Set c = .Find("Other", .Cells(1, 1), _
LookIn:=xlValues, MatchCase:=False)
If Not c Is Nothing Then
Do
lastrow = c.Row
c.Offset(2, 0).Resize(1).EntireRow.Insert
If i = 1 Then firstrow = firstrow + 2
Set c = .FindNext(c)
Loop While c.Row > lastrow
End If
End With
End Sub

might be what you want.

--
Regards,
Tom Ogilvy





.
 
Back
Top