PC Review


Reply
Thread Tools Rate Thread

Adding rows dynamically via macro

 
 
sleepingdragon2k2
Guest
Posts: n/a
 
      28th Nov 2006
Hi,

I understand that if I add 4 rows from row 17 onwards, the command
reads as follows:

Sub Insert()
Rows("17:20").Select
Application.CutCopyMode = False
Selection.Insert Shift:=xlDown
End Sub

I would like to modify this for 3 scenarios:

Scenario 1: Now, what if I don't specify 4 rows, but I want it to read
the number-of-rows-to-be-added from a certain cell from a different
worksheet eg: T4 or cell(4, 20) from worksheet 2, because that number
is to modifiable?

Scenario 2: What if I want to add 4 rows, but not necessarily from row
17 - instead, I might want to add 4 rows from any initial row?

Scenario 3: Now combine the 2 scenarios. What if for row 4, I want it
to add a number of rows specified in cell(4, 20) and then for row 5, I
want to add a number of rows specified in cell (5, 20) and so on, for
100 times?

Thanking you in advance.

SD

 
Reply With Quote
 
 
 
 
=?Utf-8?B?SmltIFRob21saW5zb24=?=
Guest
Posts: n/a
 
      28th Nov 2006
Something like this should do the trick. It uses the value in sheet 2 A1 to
determine which row to start at and A2 to determine haow many rows to
insert...

Sub InsertRows()
With Sheets("Sheet2")
Sheets("Sheet1").Rows(.Range("A1")).Resize(.Range("A2")).Insert
End With
End Sub
--
HTH...

Jim Thomlinson


"sleepingdragon2k2" wrote:

> Hi,
>
> I understand that if I add 4 rows from row 17 onwards, the command
> reads as follows:
>
> Sub Insert()
> Rows("17:20").Select
> Application.CutCopyMode = False
> Selection.Insert Shift:=xlDown
> End Sub
>
> I would like to modify this for 3 scenarios:
>
> Scenario 1: Now, what if I don't specify 4 rows, but I want it to read
> the number-of-rows-to-be-added from a certain cell from a different
> worksheet eg: T4 or cell(4, 20) from worksheet 2, because that number
> is to modifiable?
>
> Scenario 2: What if I want to add 4 rows, but not necessarily from row
> 17 - instead, I might want to add 4 rows from any initial row?
>
> Scenario 3: Now combine the 2 scenarios. What if for row 4, I want it
> to add a number of rows specified in cell(4, 20) and then for row 5, I
> want to add a number of rows specified in cell (5, 20) and so on, for
> 100 times?
>
> Thanking you in advance.
>
> SD
>
>

 
Reply With Quote
 
=?Utf-8?B?SmltIFRob21saW5zb24=?=
Guest
Posts: n/a
 
      28th Nov 2006
Sorry, I forgot to mention that I did not understand you requirement "and so
on, for
100 times"???
--
HTH...

Jim Thomlinson


"Jim Thomlinson" wrote:

> Something like this should do the trick. It uses the value in sheet 2 A1 to
> determine which row to start at and A2 to determine haow many rows to
> insert...
>
> Sub InsertRows()
> With Sheets("Sheet2")
> Sheets("Sheet1").Rows(.Range("A1")).Resize(.Range("A2")).Insert
> End With
> End Sub
> --
> HTH...
>
> Jim Thomlinson
>
>
> "sleepingdragon2k2" wrote:
>
> > Hi,
> >
> > I understand that if I add 4 rows from row 17 onwards, the command
> > reads as follows:
> >
> > Sub Insert()
> > Rows("17:20").Select
> > Application.CutCopyMode = False
> > Selection.Insert Shift:=xlDown
> > End Sub
> >
> > I would like to modify this for 3 scenarios:
> >
> > Scenario 1: Now, what if I don't specify 4 rows, but I want it to read
> > the number-of-rows-to-be-added from a certain cell from a different
> > worksheet eg: T4 or cell(4, 20) from worksheet 2, because that number
> > is to modifiable?
> >
> > Scenario 2: What if I want to add 4 rows, but not necessarily from row
> > 17 - instead, I might want to add 4 rows from any initial row?
> >
> > Scenario 3: Now combine the 2 scenarios. What if for row 4, I want it
> > to add a number of rows specified in cell(4, 20) and then for row 5, I
> > want to add a number of rows specified in cell (5, 20) and so on, for
> > 100 times?
> >
> > Thanking you in advance.
> >
> > SD
> >
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding rows dynamically via macro sleepingdragon2k2 Microsoft Excel Programming 1 28th Nov 2006 08:45 PM
Adding rows dynamically via macro sleepingdragon2k2 Microsoft Excel Programming 0 28th Nov 2006 06:46 PM
Adding rows dynamically to a datagrid Ram Microsoft ASP .NET 2 20th Feb 2006 11:06 AM
Re: Adding rows dynamically to datagrid Saravana [MVP] Microsoft ASP .NET 0 24th May 2004 04:51 AM
Re: Adding rows dynamically to datagrid Andy Gaskell Microsoft ASP .NET 0 22nd May 2004 10:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:19 AM.