+ Reply to Thread
Results 1 to 3 of 3

Code to insert and copy down

  1. #1
    Registered User
    Join Date
    04-08-2008
    Posts
    18

    Code to insert and copy down

    Hi,

    I've used the below code to insert a number of lines between each row automatically which works as intended. What i also need to do is copy down the data in the first row at each insert. For example the below 'data' would have 27 rows between each other, but instead of blank cells there is the same number copied down 27 times. Can someone help me with amending the code?

    Data:

    999253139
    999252957

    Code:

    Sub InsertRows()
    Dim i As Long, nRows As Integer, nEvery As Integer
    Application.ScreenUpdating = False
    nRows = 27 'number of rows to insert
    nEvery = 1 'number of rows to skip between insertions
    i = nEvery + 1 'first row for insertion
    While Not IsEmpty(Cells(i, 1)) 'stop inserting when come to empty cell
    Rows(i & ":" & i + nRows - 1).Insert
    i = i + nRows + nEvery
    Wend
    End Sub

    Once i've done that i also want to insert numbers 1-28 in column B againest each row and replicate that at each change.

    The final would look like the below:

    column A column B
    999253139 1
    999253139 2
    999253139 3
    999253139 4
    999253139 5
    999253139 6
    999253139 7
    999253139 8
    999253139 9
    999253139 10
    999253139 11
    etc
    etc

    then

    999252957 1
    999252957 2
    999252957 3
    etc
    etc

    Many Thanks

  2. #2
    Forum Contributor
    Join Date
    02-04-2010
    Location
    Hertfordshire, England
    MS-Off Ver
    Office 2007 (home) Office 365 (work)
    Posts
    134

    Re: Code to insert and copy down

    Hi stevedarby02

    I believe that you need to add the following code at the end of your code to achieve your desired results

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    04-08-2008
    Posts
    18

    Re: Code to insert and copy down

    Quote Originally Posted by excelxx View Post
    Hi stevedarby02

    I believe that you need to add the following code at the end of your code to achieve your desired results

    Please Login or Register  to view this content.
    Fantastic, thank you.

    Steve

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1