+ Reply to Thread
Results 1 to 7 of 7

Copy data from a certain range and past multiple times.

Hybrid View

Butehawk Copy data from a certain... 04-29-2010, 06:22 PM
JBeaucaire Re: Copy data from a certain... 04-29-2010, 07:53 PM
Butehawk Re: Copy data from a certain... 04-29-2010, 09:23 PM
JBeaucaire Re: Copy data from a certain... 04-30-2010, 12:56 AM
royUK Re: Copy data from a certain... 04-30-2010, 01:12 AM
Butehawk Re: Copy data from a certain... 04-30-2010, 12:40 PM
JBeaucaire Re: Copy data from a certain... 04-30-2010, 09:15 PM
  1. #1
    Registered User
    Join Date
    01-13-2010
    Location
    Erskine
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    34

    Copy data from a certain range and past multiple times.

    I have a range of data that requires to be copied and pasted below each other a huge number of times. Each set of data has cells in it that are linked to cells in a single row of a particular master spreadsheet. Each time the data is pasted the linked cell row number has to increase by one to input the data from the next row.
    I have attached a sheet to show how I need the sheet to be.
    The first range contains all the linked data in the correct cells.
    I can copy and past the data as done here and then use the replace command to change the row numbers but there must be an easier way .Can anybody help.
    Attached Files Attached Files
    Last edited by Butehawk; 04-30-2010 at 01:36 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Copy data from a certain range and past multiple times.

    This is a bit rough, but it does it. Just setup the first set of data in D3:I17, delete anything below it and run the macro:
    Option Explicit
    
    Sub BruteCopyChange()
    Dim CopyRNG As Range
    Dim CopyCNT As Long
    Dim CopyNum As Long
    Dim NextRow As Long
    
    CopyCNT = Application.InputBox("Copy how many times?", "Copy Count", 2100, Type:=1)
    If CopyCNT = 0 Then Exit Sub
    
    Application.ScreenUpdating = False
    Set CopyRNG = Range("D3:I7")
    NextRow = 8
    
    For CopyNum = 1 To CopyCNT
        CopyRNG.Copy Range("D" & NextRow)
        Range("D" & NextRow & ":D" & NextRow + 4 & _
             ",F" & NextRow & ":F" & NextRow + 4 & _
             ",I" & NextRow & ":I" & NextRow + 4).Replace What:="$3", _
            Replacement:="$" & 3 + CopyNum, LookAt:=xlPart, SearchOrder:=xlByRows, _
            MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
        NextRow = NextRow + 5
    Next CopyNum
    
    CopyRNG.EntireColumn.AutoFit
    Application.ScreenUpdating = True
    End Sub
    Attached Files Attached Files
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    01-13-2010
    Location
    Erskine
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    34

    Re: Copy data from a certain range and past multiple times.

    I had to make some changes to this to fit my data sheet. but it will not run the macro.What have I done wrong.
    The data I need to copy is in the range D3:V66.
    Any column of this data could have a reference to the row in the master data sheet. So I included these rows in the macro.
    When I try to run it it highlights the "option Explicit" line and says "Invalid inside Procedure".

    Sub pastemanyrowsinsequence()
    '
    ' pastemanyrowsinsequence Macro
    ' Macro recorded 30/04/2010 by Roger
    '
    
        Option Explicit
    
    Sub BruteCopyChange()
    Dim CopyRNG As Range
    Dim CopyCNT As Long
    Dim CopyNum As Long
    Dim NextRow As Long
    
    CopyCNT = Application.InputBox("Copy how many times?", "Copy Count", 10, Type:=1)
    If CopyCNT = 0 Then Exit Sub
    
    Application.ScreenUpdating = False
    Set CopyRNG = Range("D3:V66")
    NextRow = 67
    
    For CopyNum = 1 To CopyCNT
        CopyRNG.Copy Range("D" & NextRow)
        Range("D" & NextRow & ":D" & NextRow + 63 & _
              ",E" & NextRow & ":E" & NextRow + 63 & _
              ",F" & NextRow & ":F" & NextRow + 63 & _
              ",G" & NextRow & ":G" & NextRow + 63 & _
              ",H" & NextRow & ":H" & NextRow + 63 & _
              ",I" & NextRow & ":I" & NextRow + 63 & _
              ",J" & NextRow & ":J" & NextRow + 63 & _
              ",K" & NextRow & ":K" & NextRow + 63 & _
              ",L" & NextRow & ":L" & NextRow + 63 & _
              ",M" & NextRow & ":M" & NextRow + 63 & _
              ",N" & NextRow & ":N" & NextRow + 63 & _
              ",O" & NextRow & ":O" & NextRow + 63 & _
              ",P" & NextRow & ":P" & NextRow + 63 & _
              ",Q" & NextRow & ":Q" & NextRow + 63 & _
              ",R" & NextRow & ":R" & NextRow + 63 & _
              ",S" & NextRow & ":S" & NextRow + 63 & _
              ",T" & NextRow & ":T" & NextRow + 63 & _
              ",U" & NextRow & ":V" & NextRow + 63 & _
              ",V" & NextRow & ":V" & NextRow + 63).Replace What:="$3", _
            Replacement:="$" & 3 + CopyNum, LookAt:=xlPart, SearchOrder:=xlByRows, _
            MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
        NextRow = NextRow + 64
    Next CopyNum
    
    CopyRNG.EntireColumn.AutoFit
    Application.ScreenUpdating = True
    End Sub






    I set the copy count to 10 to try it out,on the first ten data ranges.

    Roger
    Last edited by Butehawk; 04-30-2010 at 12:37 PM.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Copy data from a certain range and past multiple times.

    Why wouldn't you post up a sample sheet the matched the layout of your actual workbook exactly? Oversimplifying just makes more work out of the process for all. Have an updated (better) example workbook?

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Copy data from a certain range and past multiple times.

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  6. #6
    Registered User
    Join Date
    01-13-2010
    Location
    Erskine
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    34

    Re: Copy data from a certain range and past multiple times.

    Sorry RoyUK,
    I am new to all this and on a steep learning curve.
    I have learnt something new again.

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Copy data from a certain range and past multiple times.

    It appears you copied my macro inside something you already had there. Delete everything ABOVE the Option Explicit and try it again.

+ 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