+ Reply to Thread
Results 1 to 11 of 11

Copy and Paste Cell X number of times based on Adjacent Cell

  1. #1
    Registered User
    Join Date
    11-16-2016
    Location
    California
    MS-Off Ver
    2010
    Posts
    8

    Copy and Paste Cell X number of times based on Adjacent Cell

    Hi everyone,
    I am pretty new to creating Macro's in Excel and wanted to make one run that would paste the value down a column sequentialy based on the number adjacent to the cell.
    Ex.
    Bob 10
    Marley 12
    Michael 8
    Jackson 5

    The output will be something like the following down a column.
    Bob x10
    Marley x12
    Michael x8
    Jackson x5

    Thanks in advance!

  2. #2
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Copy and Paste Cell X number of times based on Adjacent Cell

    Assuming names running A1:A4, numbers B1:B4:

    Please Login or Register  to view this content.
    Make Mom proud: Add to my reputation if I helped out!

    Make the Moderators happy: Mark the Thread as Solved if your question was answered!

  3. #3
    Registered User
    Join Date
    11-16-2016
    Location
    California
    MS-Off Ver
    2010
    Posts
    8

    Re: Copy and Paste Cell X number of times based on Adjacent Cell

    Quote Originally Posted by daffodil11 View Post
    Assuming names running A1:A4, numbers B1:B4:

    Please Login or Register  to view this content.
    Thanks for the fast reply I'll try it out now, would you happen to know of any resources that I can refer to for learning Macro's?
    Last edited by GabeGabe; 12-06-2016 at 01:38 PM.

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Copy and Paste Cell X number of times based on Adjacent Cell

    Or build list in array and write to worksheet in 1 go.

    Please Login or Register  to view this content.
    Last edited by bakerman2; 12-06-2016 at 01:41 PM.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  5. #5
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Copy and Paste Cell X number of times based on Adjacent Cell

    Please Login or Register  to view this content.

  6. #6
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Copy and Paste Cell X number of times based on Adjacent Cell

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    11-16-2016
    Location
    California
    MS-Off Ver
    2010
    Posts
    8

    Re: Copy and Paste Cell X number of times based on Adjacent Cell

    Hi
    For clarification, I am using Google Sheets App Script Editor.

    I am getting the error
    Missing ( before function parameters.

    function Sub CopyDown()
    Dim i As Long, lr As Long
    With ActiveSheet
    lr = .Cells(Rows.Count, 1).End(xlUp).Row
    For i = lr To 2 Step -1
    .Cells(i + 1, 1).Resize(.Cells(i, 2).Value - 1).EntireRow.Insert
    .Cells(i, 1).Resize(.Cells(i, 1).Offset(, 1).Value) = .Cells(i, 1).Value
    Next
    End With
    End Sub

  8. #8
    Registered User
    Join Date
    11-16-2016
    Location
    California
    MS-Off Ver
    2010
    Posts
    8

    Re: Copy and Paste Cell X number of times based on Adjacent Cell

    Hi
    For clarification, I am using Google Sheets App Script Editor.

    I am getting the error
    Missing ( before function parameters.

    function Sub CopyDown()
    Dim i As Long, lr As Long
    With ActiveSheet
    lr = .Cells(Rows.Count, 1).End(xlUp).Row
    For i = lr To 2 Step -1
    .Cells(i + 1, 1).Resize(.Cells(i, 2).Value - 1).EntireRow.Insert
    .Cells(i, 1).Resize(.Cells(i, 1).Offset(, 1).Value) = .Cells(i, 1).Value
    Next
    End With
    End Sub

  9. #9
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Copy and Paste Cell X number of times based on Adjacent Cell

    Delete the word function before Sub.

    BTW
    There were 3 different codes provided. Did you even try the other 2?

  10. #10
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Copy and Paste Cell X number of times based on Adjacent Cell

    Quote Originally Posted by GabeGabe View Post
    Hi
    For clarification, I am using Google Sheets App Script Editor.

    I am getting the error
    Missing ( before function parameters.

    function Sub CopyDown()
    Dim i As Long, lr As Long
    With ActiveSheet
    lr = .Cells(Rows.Count, 1).End(xlUp).Row
    For i = lr To 2 Step -1
    .Cells(i + 1, 1).Resize(.Cells(i, 2).Value - 1).EntireRow.Insert
    .Cells(i, 1).Resize(.Cells(i, 1).Offset(, 1).Value) = .Cells(i, 1).Value
    Next
    End With
    End Sub
    The sub procedure is not written as a function and would not work as a UDF. You could use it with a Form Controls button which can be created by going to your Developer menu on the ribbon, Click Insert then click on the command button from the Forms Control tool box. Place the button where you want it to appear on the worksheet by moving the mouse pointer corsshairs (+) to that location and left click. A dialog box will pop up that has 'Assign Macro' option. Click that to get the Macro dialogs box and assign the macro to the button. Later versiions of Excel go directly to the macro dialog box when the button is created.
    Last edited by JLGWhiz; 12-07-2016 at 09:15 AM.

  11. #11
    Registered User
    Join Date
    11-16-2016
    Location
    California
    MS-Off Ver
    2010
    Posts
    8

    Re: Copy and Paste Cell X number of times based on Adjacent Cell

    Quote Originally Posted by bakerman2 View Post
    Delete the word function before Sub.

    BTW
    There were 3 different codes provided. Did you even try the other 2?
    Yes,
    They all had the same error on Google Sheet. I just provided the shortest example.

+ 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] Copy paste data number of times based on cell value
    By shreeja178 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-19-2016, 06:19 AM
  2. [SOLVED] Copy rows/range and paste n number of times based on last used cell in Column A
    By skonduru in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-29-2016, 02:30 PM
  3. Replies: 1
    Last Post: 01-03-2014, 03:01 AM
  4. Copy the value in a cell, X times to adjacent cells
    By mselbie in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-16-2013, 02:00 PM
  5. Copy a row and paste it a number of times based on a cell value
    By glrubens in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-02-2013, 12:37 PM
  6. Replies: 0
    Last Post: 05-18-2012, 11:18 PM
  7. VBA; copy paste number of times based on cell value
    By photopidge in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-25-2011, 03:17 AM

Tags for this Thread

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