Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Insert Varying # Rows

I got this macro (below) on this DG a while back and used it several times.
I just tried to modify it to insert variable rows in column B and it doesnt
work. I get an error at:

For I = 1 To Cells(myRow, 1)

I have not idea why this causes an error. Does anyone have a clue? Thanks
in advance!!


Sub InsertVarRows()
Dim myRow As Long

lastcell = Cells(Rows.Count, "B").End(xlUp).Row

myRow = 1
Do Until myRow = lastcell
For I = 1 To Cells(myRow, 1)

If Cells(myRow, 1) < "" Then
Cells(myRow + 1, 1).Select
Selection.Insert shift:=xlDown
End If

Next
lastcell = Cells(Rows.Count, "B").End(xlUp).Row
myRow = myRow + 1
Loop
End Sub


--
RyGuy
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default Insert Varying # Rows

Does column A contain the number of cells to insert? Because you are
saying For I = 1 To Cells(myRow, 1) . Cells(myRow,1) is going to
return the value from whatever is in column A and whatever row myRow
is set to. So, if Cells(myRow, 1) = "Bob", you can see why the For
Next wouldn't work. That's about all I can tell you without seeing
your data.
ryguy7272 wrote:
I got this macro (below) on this DG a while back and used it several times.
I just tried to modify it to insert variable rows in column B and it doesn't
work. I get an error at:

For I = 1 To Cells(myRow, 1)

I have not idea why this causes an error. Does anyone have a clue? Thanks
in advance!!


Sub InsertVarRows()
Dim myRow As Long

lastcell = Cells(Rows.Count, "B").End(xlUp).Row

myRow = 1
Do Until myRow = lastcell
For I = 1 To Cells(myRow, 1)

If Cells(myRow, 1) < "" Then
Cells(myRow + 1, 1).Select
Selection.Insert shift:=xlDown
End If

Next
lastcell = Cells(Rows.Count, "B").End(xlUp).Row
myRow = myRow + 1
Loop
End Sub


--
RyGuy


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Insert Varying # Rows

JW, you are absolutely right. I changed the code to: For I = 1 To
Cells(myRow, 2)
Now, it works! I can't understand why I didn't see that. Oh well...
Thanks for your time!!

Cordially,
Ryan---


--
RyGuy


"JW" wrote:

Does column A contain the number of cells to insert? Because you are
saying For I = 1 To Cells(myRow, 1) . Cells(myRow,1) is going to
return the value from whatever is in column A and whatever row myRow
is set to. So, if Cells(myRow, 1) = "Bob", you can see why the For
Next wouldn't work. That's about all I can tell you without seeing
your data.
ryguy7272 wrote:
I got this macro (below) on this DG a while back and used it several times.
I just tried to modify it to insert variable rows in column B and it doesn't
work. I get an error at:

For I = 1 To Cells(myRow, 1)

I have not idea why this causes an error. Does anyone have a clue? Thanks
in advance!!


Sub InsertVarRows()
Dim myRow As Long

lastcell = Cells(Rows.Count, "B").End(xlUp).Row

myRow = 1
Do Until myRow = lastcell
For I = 1 To Cells(myRow, 1)

If Cells(myRow, 1) < "" Then
Cells(myRow + 1, 1).Select
Selection.Insert shift:=xlDown
End If

Next
lastcell = Cells(Rows.Count, "B").End(xlUp).Row
myRow = myRow + 1
Loop
End Sub


--
RyGuy



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
Insert totals after varying rows of data prodeji Excel Programming 1 February 13th 07 01:40 AM
Selectdown Macro w/ varying rows Ron de Bruin Excel Programming 1 December 7th 06 10:22 PM
SUMPRODUCT with varying # of rows Ren Excel Worksheet Functions 5 June 27th 06 11:28 PM
Sum varying number of rows LSkarbek Excel Programming 3 April 12th 06 04:02 PM
Transfer rows with varying criteria chris100[_33_] Excel Programming 0 October 13th 05 09:20 PM


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