Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,836
Default Insert Variable Number of Rows; With Loop

Insert Variable Number of Rows

I was playing with some VBA code that would permit me to choose an insertion
point, lets say A4, and then insert variable numbers of rows, based on the
values in a certain column, lets say column A€¦and of course it will start at
the insertion point that the user chooses So far, this is what I have:

Sub InsertAnyRows()

Dim insertNumber As Range
Dim insertStart As Range
Dim redRng As Range
Dim i As Integer
Set insertNumber = Application.InputBox _
(Prompt:="Select a point to insert rows.", Title:="Add a row", Type:=8)

insertNumber.Select
If insertNumber <= 0 Then
MsgBox ("Invalid Number Entered")
Exit Sub
End If

Dim lastrow As Integer
ActiveCell.Offset(1, 0).Select
Selection.EntireRow.Resize(insertNumber).Insert
ActiveCell.Offset(1, 0).Select
Do
For x = i To 1
Set redRng = Range("A1", Range("A10").End(xlUp))
For Each Cell In redRng
Selection.EntireRow.Resize(insertNumber).Insert
If ActiveCell.Offset(0, 0).Select = "" Then
ActiveCell.Offset(1, 0).Select
Selection.EntireRow.Resize(insertNumber).Insert
End If
Next Cell
Next x
Loop Until ActiveCell.Offset(0, 0).Select = ""
End Sub


There is some problem with the loop and I just cant figure it out. Please
help!!!
Thanks so much!!
Ryan--

--
RyGuy
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 60
Default Insert Variable Number of Rows; With Loop

For starters I don't see where I is set to anything, and if I is higher than
1 than you would need for x=i to 1 step -1
--
-John Northwest11
Please rate when your question is answered to help us and others know what
is helpful.


"ryguy7272" wrote:

Insert Variable Number of Rows

I was playing with some VBA code that would permit me to choose an insertion
point, lets say A4, and then insert variable numbers of rows, based on the
values in a certain column, lets say column A€¦and of course it will start at
the insertion point that the user chooses So far, this is what I have:

Sub InsertAnyRows()

Dim insertNumber As Range
Dim insertStart As Range
Dim redRng As Range
Dim i As Integer
Set insertNumber = Application.InputBox _
(Prompt:="Select a point to insert rows.", Title:="Add a row", Type:=8)

insertNumber.Select
If insertNumber <= 0 Then
MsgBox ("Invalid Number Entered")
Exit Sub
End If

Dim lastrow As Integer
ActiveCell.Offset(1, 0).Select
Selection.EntireRow.Resize(insertNumber).Insert
ActiveCell.Offset(1, 0).Select
Do
For x = i To 1
Set redRng = Range("A1", Range("A10").End(xlUp))
For Each Cell In redRng
Selection.EntireRow.Resize(insertNumber).Insert
If ActiveCell.Offset(0, 0).Select = "" Then
ActiveCell.Offset(1, 0).Select
Selection.EntireRow.Resize(insertNumber).Insert
End If
Next Cell
Next x
Loop Until ActiveCell.Offset(0, 0).Select = ""
End Sub


There is some problem with the loop and I just cant figure it out. Please
help!!!
Thanks so much!!
Ryan--

--
RyGuy

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,836
Default Insert Variable Number of Rows; With Loop

I tried replacing:
For x = i To 1

with:
For x=i to 1 step -1

This causes Excel to enter a perpetual loop.
I think I am close; any other suggestions?
Thanks in advance!!
Ryan--


--
RyGuy


"John Bundy" wrote:

For starters I don't see where I is set to anything, and if I is higher than
1 than you would need for x=i to 1 step -1
--
-John Northwest11
Please rate when your question is answered to help us and others know what
is helpful.


"ryguy7272" wrote:

Insert Variable Number of Rows

I was playing with some VBA code that would permit me to choose an insertion
point, lets say A4, and then insert variable numbers of rows, based on the
values in a certain column, lets say column A€¦and of course it will start at
the insertion point that the user chooses So far, this is what I have:

Sub InsertAnyRows()

Dim insertNumber As Range
Dim insertStart As Range
Dim redRng As Range
Dim i As Integer
Set insertNumber = Application.InputBox _
(Prompt:="Select a point to insert rows.", Title:="Add a row", Type:=8)

insertNumber.Select
If insertNumber <= 0 Then
MsgBox ("Invalid Number Entered")
Exit Sub
End If

Dim lastrow As Integer
ActiveCell.Offset(1, 0).Select
Selection.EntireRow.Resize(insertNumber).Insert
ActiveCell.Offset(1, 0).Select
Do
For x = i To 1
Set redRng = Range("A1", Range("A10").End(xlUp))
For Each Cell In redRng
Selection.EntireRow.Resize(insertNumber).Insert
If ActiveCell.Offset(0, 0).Select = "" Then
ActiveCell.Offset(1, 0).Select
Selection.EntireRow.Resize(insertNumber).Insert
End If
Next Cell
Next x
Loop Until ActiveCell.Offset(0, 0).Select = ""
End Sub


There is some problem with the loop and I just cant figure it out. Please
help!!!
Thanks so much!!
Ryan--

--
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
Pivot table row fields limit vs. number of rows in use for Excel 2 VP needs help Excel Discussion (Misc queries) 3 October 11th 06 08:11 PM
Insert Next? Or insert a variable number of records...how? Tom MacKay Excel Discussion (Misc queries) 0 April 20th 06 10:44 PM
Aling multiple sets of data by header column MarkusO Excel Discussion (Misc queries) 2 April 12th 06 07:29 PM
Return SEARCHED Column Number of Numeric Label and Value Sam via OfficeKB.com Excel Worksheet Functions 23 January 30th 06 06:16 PM
asking again, macro to insert rows Luke Excel Worksheet Functions 12 September 18th 05 06:32 PM


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