Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Increment stopvalue inside a For loop

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
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.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Increment stopvalue inside a For loop

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.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to increment within For Next Loop EagleOne Excel Discussion (Misc queries) 1 August 9th 06 04:18 PM
Loop .WebTables to increment by 1 al007 Excel Programming 0 February 24th 06 08:02 AM
Increment column in loop RyanVM[_20_] Excel Programming 4 August 24th 04 08:28 PM
Increment value inside conditional format Bill Burns Excel Programming 3 June 19th 04 08:25 PM
Increment through For Next loop hotherps[_7_] Excel Programming 3 April 8th 04 05:40 PM


All times are GMT +1. The time now is 06:33 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"