LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 42
Default For... Next Loop

Hi there, wonder if anyone can help. Relatively new to loops, and can't get
it to stop looping!!

Here's the code, trying to insert a row after every cell that has "Total for
department" (number of occurences vary each time), and whilst the row gets
added, it then loops back to the beginning and adds multiple rows.

Any thoughts?

Thanks, Mike

Sub Abbey3()

Dim i As Integer
Dim thisrow As Integer

For i = 1 To Selection.CurrentRegion.Rows.Count - 1

Cells.Find(What:="Total for Department", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate

thisrow = Selection.Row
Rows(thisrow + 1).EntireRow.Insert

ActiveCell.Offset(1, 0).Select

Next i

End Sub

 
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
do..loop Anna Excel Discussion (Misc queries) 6 June 20th 07 01:10 PM
Loop help PaulW Excel Discussion (Misc queries) 0 May 8th 06 04:00 PM
getting out of a if loop rk0909 Excel Discussion (Misc queries) 3 April 11th 06 03:55 PM
Do Loop Noemi Excel Discussion (Misc queries) 0 December 8th 05 10:43 PM
Which loop to use theguz Excel Discussion (Misc queries) 2 August 5th 05 07:01 PM


All times are GMT +1. The time now is 02:18 AM.

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"