Increment stopvalue inside a For loop

R

Revenger

Hi all !
Problem:
I'm using For Next loop to go through cells that have some data ...

UsedRange.Select
rownumber = Selection.Rows.COunt *(let's say 50)*
For i = 1 to rownumber
If <something> then
Rows.Insert
rownubmer = rownumber + 1
End if
Next i

But my loop stops at 50 ! How can I increment the stopvalue from inside a
FOR NEXT loop ?

Thanks !
--
Pozdrav
Revenger
26.5.2006 09:32:55
Jednom su proizveli Chuck Norris toalet papir, ali papir nije dopustao da
itko sere po njemu.
 
N

Norman Jones

Hi Revenger,

When inserting (or deleting) rows, it is generally easier to work from
bottom to top.

Try something like:
'=============>>
Public Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet
Dim i As Long
Dim LastRow As Long

Set WB = Workbooks("YourBook.xls") '<<===== CHANGE
Set SH = WB.Sheets("Sheet1") '<<===== CHANGE

With SH
LastRow = .Cells(Rows.Count, "A").End(xlUp).Row

For i = LastRow To 1 Step -1
If .Cells(i, "A").Value = 200 Then
.Rows(i).Offset(1).Insert
End If
Next i
End With

End Sub
'<<=============
 
R

Revenger

On Fri, 26 May 2006 09:36:41 +0200, Revenger wrote:

Got it done !
I used WHILE loop and everything works fine !

--
Pozdrav
Revenger
26.5.2006 10:17:10
Jednom su proizveli Chuck Norris toalet papir, ali papir nije dopustao da
itko sere po njemu.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top