View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default Increment stopvalue inside a For loop

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
'<<=============


---
Regards,
Norman



"Revenger" wrote in message
.. .
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.