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 final value in for statement

Can anyone help me please with this macro.

If I add a row to a spreadsheet I want to increment the final value in a for
statement but it doesn't seem to work.

ie

For i = 4 To lastrow

(if statement which can add a row)
lastrow = lastrow + 1
Else: End If
next i


When I run this lastrow doesn't increment and last row stays at the original
value.

Thanks

Ian





  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default Increment final value in for statement

Hi Ian,

When the For staement is executed, the current value value of lastrow is
retained as a counter for i for the whole of the For-Next loop.

Try using a counter in DO - LOOP UNTIL lastrow counter.

Regards,
Don

"nicoll" wrote in message
...
Can anyone help me please with this macro.

If I add a row to a spreadsheet I want to increment the final value in a

for
statement but it doesn't seem to work.

ie

For i = 4 To lastrow

(if statement which can add a row)
lastrow = lastrow + 1
Else: End If
next i


When I run this lastrow doesn't increment and last row stays at the

original
value.

Thanks

Ian







  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 691
Default Increment final value in for statement

Hi Ian,
If you are running through a range and inserting or deleting
rows you want to start from the bottom. Otherwise, the lastcell is not
the only problem you would have -- you would also be skipping rows
or processing rows twice.

For i = lastrow to 4 step -1
....
next i

For more information on inserting and deleting rows and maintaining
your formulas see
Insert a Row using a Macro to maintain formulas
http://www.mvps.org/dmcritchie/excel/insrtrow.htm
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"nicoll" wrote in message ...
Can anyone help me please with this macro.

If I add a row to a spreadsheet I want to increment the final value in a for
statement but it doesn't seem to work.

ie

For i = 4 To lastrow

(if statement which can add a row)
lastrow = lastrow + 1
Else: End If
next i


When I run this lastrow doesn't increment and last row stays at the original
value.

Thanks

Ian







  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Problem solved Increment final value in for statement

Thanks Don's answer solved the problem.





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
Final entry in array Esradekan Excel Worksheet Functions 5 November 17th 09 08:11 AM
final return! via135 Excel Worksheet Functions 5 January 11th 08 11:00 AM
Final day of month B Excel Worksheet Functions 3 July 25th 07 12:49 AM
My Final #DIV/0! that I'd like to say Goodbye to! Dan the Man[_2_] Excel Worksheet Functions 20 July 23rd 07 05:40 PM
Help Finding the Final Row No Name Excel Programming 7 May 21st 04 03:13 AM


All times are GMT +1. The time now is 01:09 PM.

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

About Us

"It's about Microsoft Excel"