+ Reply to Thread
Results 1 to 18 of 18

Copy Row X Times down Macro

  1. #1
    Registered User
    Join Date
    01-09-2015
    Location
    Illinois, USA
    MS-Off Ver
    2013
    Posts
    63

    Copy Row X Times down Macro

    Need some help ?

    Getting error Run-time error '1004': on execution of macro to copy contents on row 8 Columns B,C,D,E

    When I click on debug it shows hanging up on this row

    For Each rngCell In ThisWorkbook.Worksheets("Sheet1").Range("B11:D9" & Cells(Rows.Count, 4).End(x1Up).Row)

    The "5" in cell (B:8) is the number of times I want it copied


    B:8 5
    C:8 Semi
    D:8 CM-13
    E:8 RS-Allied


    Sub CopyRowsXTimes()

    Dim rngCell As Range

    This Workbook.Worksheets("Sheet1").Cells.ClearContents

    For Each rngCell In ThisWorkbook.Worksheets ("Sheet1").Range("B11:D9" & Cells(Rows.Count, 4).End (x1Up).Row)

    With ThisWorkbook.Worksheets("Sheet1")

    .Cells(.UsedRange.SpecialCells(x1CellTypeLastCell).Row, 1).Resize(rngCell.Value, 4).Value = rngCell.Offset(, -3).Resize(1, 4).Value


    (code is below)

    Sub CopyRowsXTimes()

    Dim rngCell As Range

    'This Workbook.Worksheets("Sheet1").Cells.ClearContents
    For Each rngCell In ThisWorkbook.Worksheets("Sheet1").Range("B11:D9" & Cells(Rows.Count, 4).End(x1Up).Row)

    With ThisWorkbook.Worksheets("Sheet1")

    .Cells(.UsedRange.SpecialCells(x1CellTypeLastCell).Row, 1).Resize(rngCell.Value, 4).Value = rngCell.Offset(, -3).Resize(1, 4).Value

    End With
    Next rngCell

    Set rngCell = Nothing

    End Sub



    Thanks in advance for your help.
    Dennis

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Copy Row X Times down Macro

    Try changing this:

    Please Login or Register  to view this content.
    To this:

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    01-09-2015
    Location
    Illinois, USA
    MS-Off Ver
    2013
    Posts
    63

    Re: Copy Row X Times down Macro

    Jersey,

    I changed the code, same thing happens ?

    Dennis

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,626

    Re: Copy Row X Times down Macro

    It's xLUp not x1Up.

    Also xLCellTypeLastCell not x1CellTypeLastCell.

    PS The L will change to lower case.
    If posting code please use code tags, see here.

  5. #5
    Registered User
    Join Date
    01-09-2015
    Location
    Illinois, USA
    MS-Off Ver
    2013
    Posts
    63

    Re: Copy Row X Times down Macro

    When I try to edit the code and enter xLUp it changes it back to x1Up ??

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,626

    Re: Copy Row X Times down Macro

    Are you sure it isn't changing it to xlUp?

  7. #7
    Registered User
    Join Date
    01-09-2015
    Location
    Illinois, USA
    MS-Off Ver
    2013
    Posts
    63

    Re: Copy Row X Times down Macro

    Here is it copied and pasted

    [For Each rngCell In ThisWorkbook.Worksheets("Sheet1").Range("B11:D" & Cells(Rows.Count, 4).End(xlUp).Row)]

  8. #8
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Copy Row X Times down Macro

    Can you attach a sample copy of the file which produces the error?

  9. #9
    Registered User
    Join Date
    01-09-2015
    Location
    Illinois, USA
    MS-Off Ver
    2013
    Posts
    63

    Re: Copy Row X Times down Macro

    Yes, how do I attach a file in my reply ?

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,626

    Re: Copy Row X Times down Macro

    What you posted has xlUp not x1Up.

    PS Can you add code tags when posting code?

  11. #11
    Registered User
    Join Date
    01-09-2015
    Location
    Illinois, USA
    MS-Off Ver
    2013
    Posts
    63

    Re: Copy Row X Times down Macro

    Here it is ---- Nothing critical in file, just building it

    On Sheet 1


    Copy of Trucking Orders 3-28-2015.xlsm

  12. #12
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Copy Row X Times down Macro

    There's no data in that range in Sheet1??

  13. #13
    Registered User
    Join Date
    01-09-2015
    Location
    Illinois, USA
    MS-Off Ver
    2013
    Posts
    63

    Re: Copy Row X Times down Macro

    Really ??

    B:8 , C:8, D:8, & E:8

    There is in the file sent. Maybe I am doing something wrong ??

  14. #14
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Copy Row X Times down Macro

    Your code references "B9:D" & Lastrow.

    Please Login or Register  to view this content.
    What is the code attempting to do?

  15. #15
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Copy Row X Times down Macro

    Does this do what you want?

    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    01-09-2015
    Location
    Illinois, USA
    MS-Off Ver
    2013
    Posts
    63

    Re: Copy Row X Times down Macro

    I am trying to use the code to look at a cell and if there is say number 5, to copy another cell 5 times down in rows

    Thanks

  17. #17
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,626

    Re: Copy Row X Times down Macro

    You can't offset 3 columns to the left from column B.

    Also, shouldn't you only be looping down column B?

  18. #18
    Registered User
    Join Date
    01-09-2015
    Location
    Illinois, USA
    MS-Off Ver
    2013
    Posts
    63

    Re: Copy Row X Times down Macro

    OK, Sorry, I guess what I was trying to say and do is this:

    I was saying if I had the data where it is and the number 5 is in the cell I wish the other 3 cells to be copied to a given range. If the code is wrong, I am looking for help correcting the code. I am just trying to copy X times, select a range and copy to any range I select.

    Thanks for any help

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Macro to copy one row for n times in another worksheet.
    By khalidness in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-11-2014, 10:24 AM
  2. [SOLVED] Macro to copy row and multiply by n times
    By mlocy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-21-2013, 10:55 AM
  3. [SOLVED] Macro to copy sheets several times
    By Taislin in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-21-2013, 03:43 PM
  4. [SOLVED] Macro to copy a row # times onto a specific tab?
    By KPBailey in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-08-2012, 09:10 AM
  5. Macro to copy data multiple times
    By TheVril in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-19-2012, 11:31 AM

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