PC Review


Reply
Thread Tools Rate Thread

Create loop to insert two rows after every row of data

 
 
robs_drunk@hotmail.com
Guest
Posts: n/a
 
      16th Aug 2007
Hi
My Data starts at A8:C500 i have a count to find exact number of
lines.

myCount = Selection.Rows.Count

this works fine.

Now i need to the insert 2 blank lines under the first line and then
merge and center Column A and then do the same for B and C, i can do
this once but i require to repeat this for the amount of the myCount.
Below is a sort psuedo code for it that is foresee.



Count Rows
at begining insert 2 lines
Center and merge colums A,B and C for the three lines(1 data and 2
blank)
Repeat for line two of Data(which is now at A4 instead of A2 since the
insert)
until Count of rows = 0
Please help!!!!!!

 
Reply With Quote
 
 
 
 
Dallman Ross
Guest
Posts: n/a
 
      16th Aug 2007
In <(E-Mail Removed)>,
(E-Mail Removed) spake thusly:

> My Data starts at A8:C500 i have a count to find exact number of
> lines.
>
> myCount = Selection.Rows.Count
>
> this works fine.
>
> Now i need to the insert 2 blank lines under the first line and then
> merge and center Column A and then do the same for B and C, i can do
> this once but i require to repeat this for the amount of the myCount.


Maybe this will help with part of your requirement. This inserts
lines after each row of the data:

Dim i, rgTop, rgBot As Long

rgTop = 4: rgBot = 20 ' plug in your own stuff here, e.g., "myCount"

For i = rgBot To rgTop + 1 Step -1
Rows(i).Insert Shift:=xlDown
Next

It runs, but it's a bit slow. Maybe someone will tell us how to
make it faster.

=dman=

====================================
> Below is a sort psuedo code for it that is foresee.
>
>
>
> Count Rows
> at begining insert 2 lines
> Center and merge colums A,B and C for the three lines(1 data and 2
> blank)
> Repeat for line two of Data(which is now at A4 instead of A2 since the
> insert)
> until Count of rows = 0
>

 
Reply With Quote
 
=?Utf-8?B?cmVrbGFtbw==?=
Guest
Posts: n/a
 
      17th Aug 2007
Try following macro:

Sub InsertLinesAndMergeCells()
Cells(1, 1).Select
k = 1
For i = 1 To 65536
Selection.Offset(1, 0).Select
Selection.EntireRow.Insert
Selection.EntireRow.Insert
For j = 1 To 3
Range(Cells(k, j), Cells(k + 2, j)).Select
Selection.Merge
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
End With
Next j
k = k + 3
Cells(k, 1).Select
If IsEmpty(Cells(k, 1)) = True Then Exit Sub
Next i
End Sub


Regards
reklamo

"(E-Mail Removed)" wrote:

> Hi
> My Data starts at A8:C500 i have a count to find exact number of
> lines.
>
> myCount = Selection.Rows.Count
>
> this works fine.
>
> Now i need to the insert 2 blank lines under the first line and then
> merge and center Column A and then do the same for B and C, i can do
> this once but i require to repeat this for the amount of the myCount.
> Below is a sort psuedo code for it that is foresee.
>
>
>
> Count Rows
> at begining insert 2 lines
> Center and merge colums A,B and C for the three lines(1 data and 2
> blank)
> Repeat for line two of Data(which is now at A4 instead of A2 since the
> insert)
> until Count of rows = 0
> Please help!!!!!!
>
>

 
Reply With Quote
 
robs_drunk@hotmail.com
Guest
Posts: n/a
 
      20th Aug 2007
On Aug 17, 11:09 am, reklamo <rekl...@discussions.microsoft.com>
wrote:
> Try following macro:
>
> Sub InsertLinesAndMergeCells()
> Cells(1, 1).Select
> k = 1
> For i = 1 To 65536
> Selection.Offset(1, 0).Select
> Selection.EntireRow.Insert
> Selection.EntireRow.Insert
> For j = 1 To 3
> Range(Cells(k, j), Cells(k + 2, j)).Select
> Selection.Merge
> With Selection
> .HorizontalAlignment = xlCenter
> .VerticalAlignment = xlBottom
> End With
> Next j
> k = k + 3
> Cells(k, 1).Select
> If IsEmpty(Cells(k, 1)) = True Then Exit Sub
> Next i
> End Sub
>
> Regards
> reklamo
>
>
>
> "robs_dr...@hotmail.com" wrote:
> > Hi
> > My Data starts at A8:C500 i have a count to find exact number of
> > lines.

>
> > myCount = Selection.Rows.Count

>
> > this works fine.

>
> > Now i need to the insert 2 blank lines under the first line and then
> > merge and center Column A and then do the same for B and C, i can do
> > this once but i require to repeat this for the amount of the myCount.
> > Below is a sort psuedo code for it that is foresee.

>
> > Count Rows
> > at begining insert 2 lines
> > Center and merge colums A,B and C for the three lines(1 data and 2
> > blank)
> > Repeat for line two of Data(which is now at A4 instead of A2 since the
> > insert)
> > until Count of rows = 0
> > Please help!!!!!!- Hide quoted text -

>
> - Show quoted text -


Sorry this does not work can any one HELP me please

 
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
How do I create a Macro to sort data and insert blank rows & subto =?Utf-8?B?a2FyaW5tcGZh?= Microsoft Excel Worksheet Functions 2 25th Apr 2006 09:57 PM
loop to insert rows =?Utf-8?B?RmVyZ2ll?= Microsoft Excel Programming 1 18th Nov 2004 03:48 AM
Re: insert multiple rows using loop Sahil Malik Microsoft ADO .NET 0 19th Oct 2004 03:20 AM
loop to insert rows =?Utf-8?B?d2FfaGF3a3M=?= Microsoft Excel Programming 1 16th Oct 2004 09:43 PM
help on insert rows and fill down loop until end =?Utf-8?B?bWFyayBtY2dyYXRo?= Microsoft Excel Programming 1 16th Jan 2004 01:50 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:28 AM.