Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 139
Default insert variable number of rows

Hi
I would like to insert the number of rows of variable "myvalue"
i have wriiten this so far
For Each Cell In Range("MYCODES")
MYVALUE = Cell.Offset(0, 5).Value - 1
Cell.EntireRow.Rows(1, MYVALUE).Insert
Next Cell
I know insert line is incorrect but can't think what it should be
Thanks
Tina
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default insert variable number of rows

You need to loop in reverse (from highest to lowest) or you will screw up
your location.

Dim col as Long, firstRow as long, lastRow as long
Dim i as Long

col = Range("myCodes").Column
firstRow = Range("MyCodes").Rows(1).Row
lastRow = Range("Mycodes").Rows( _
Range("MyCodes").Rows.count).Row

for i = lastrow to firstrow step -1
myValue = cells(i,col).offset(0,5).Value - 1
cells(i,col).offset(1,0).Resize(myValue).EntireRow .Insert
Next

--
Regards,
Tom Ogilvy


"tina" wrote in message
...
Hi
I would like to insert the number of rows of variable "myvalue"
i have wriiten this so far
For Each Cell In Range("MYCODES")
MYVALUE = Cell.Offset(0, 5).Value - 1
Cell.EntireRow.Rows(1, MYVALUE).Insert
Next Cell
I know insert line is incorrect but can't think what it should be
Thanks
Tina



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
Summing a variable number of rows CEGavinMcGrath Excel Discussion (Misc queries) 4 August 28th 08 10:03 PM
Insert Variable Number of Rows; With Loop ryguy7272 Excel Worksheet Functions 2 December 27th 06 08:25 PM
Insert Next? Or insert a variable number of records...how? Tom MacKay Excel Discussion (Misc queries) 0 April 20th 06 10:44 PM
Insert rows in depending on criteria in variable columns jeffbert Excel Programming 2 October 4th 04 06:53 PM
Paste to variable number of rows Doug Glancy Excel Programming 0 April 1st 04 01:09 AM


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