LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
Lee Lee is offline
external usenet poster
 
Posts: 33
Default Inserting rows

I am trying to write some code to insert a row above
whenever a "1" is found in Column A. For instance, if
a "1" is found in col A, row 10, I want to insert a row
above so that all cells are moved down. My problem is
figuring out how to tell it to select a particular row
when I don't know what the row number will be. I've
written the following code:

Dim rng As Range
Dim cell As Range

Set rng = Range(Cells(2, 1), Cells(Rows.Count, 1).End
(xlUp))
For Each cell In rng
If cell.Value = 1 Then
Rows(cell).Select
Selection.Insert Shift:=xlDown

End If
Next

the problem is that because the first cell is A2, it stops
and selects that row and inserts the line at that point,
regardless of whether the cell contains a "1", and doesn't
go on to the next cell in the range.


 
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
inserting rows inbetween rows of data ? Azeem Excel Discussion (Misc queries) 1 October 27th 09 07:38 AM
Copying & Inserting Rows w/o Affecting other Rows Etc. LRay67 Excel Worksheet Functions 1 October 22nd 08 02:10 AM
inserting rows Stacie Excel Discussion (Misc queries) 3 February 19th 07 08:25 PM
Inserting Blank rows after every row upto 2500 rows Manju Excel Worksheet Functions 8 August 22nd 06 12:54 PM
inserting rows Ankur Excel Discussion (Misc queries) 0 August 11th 05 11:26 AM


All times are GMT +1. The time now is 06:55 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"