+ Reply to Thread
Results 1 to 7 of 7

Copy from static destination & paste to dynamic destination

  1. #1
    Forum Contributor
    Join Date
    08-20-2011
    Location
    Oslo
    MS-Off Ver
    MS 365
    Posts
    245

    Copy from static destination & paste to dynamic destination

    Hi!

    I need a macro to do the following:

    1. Copy text I have written in cell "J12" of Sheet1.
    2. Paste the text in a destination cell in Sheet1 specified by a dynamic row number generated in cell "J6" and a static column number (column F, which is column number 6).
    3. I will link the macro to a button in Sheet1 and the macro must execute without visibly moving around in the sheet and without leaving blinking dashed lines around the cell from which the text was copied.

    Can anyone help me with this, please?

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Copy from static destination & paste to dynamic destination

    Hi

    You mean something like

    Please Login or Register  to view this content.
    Or even simpler

    Please Login or Register  to view this content.
    Last edited by Richard Buttrey; 12-30-2015 at 11:16 AM.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Contributor
    Join Date
    08-20-2011
    Location
    Oslo
    MS-Off Ver
    MS 365
    Posts
    245

    Re: Copy from static destination & paste to dynamic destination

    Hi, thanks! Yes, that looks right. I pasted the code between Sub Macro1() and End Sub, but gets Run-time error '424': Object required. What more is needed? I'm green at VBA...

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Copy from static destination & paste to dynamic destination

    Difficult to say without seeing the problem in the context of its workbook.

    Have you used the EXACT same code I suggested or have you edited it in any way.

    The macro only contains three objects, the Sheet1 object and the two range objects. Just a guess but do you actually have a Sheet1 object?
    Sheet1 is the VBA sheet code name NOT a sheet tab name.

    Upload the workbook and no doubt we can quickly see your error.

  5. #5
    Forum Contributor
    Join Date
    08-20-2011
    Location
    Oslo
    MS-Off Ver
    MS 365
    Posts
    245

    Re: Copy from static destination & paste to dynamic destination

    Hi! You're right; I edited Sheet1 to the tab name I used for the sheet. It worked when I used your code unedited!

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Copy from static destination & paste to dynamic destination

    Quote Originally Posted by Marbleking View Post
    Hi! You're right; I edited Sheet1 to the tab name I used for the sheet. It worked when I used your code unedited!
    Hi,

    Important lesson #1 is now over.

    Always use the VBA sheet code name in macros.

    You can use the sheet tab name in a structure like Sheets("MySheetTabName").Range(...... etc., but if you change the sheet tab name in Excel then the macro will fall over as you've found. The advantage of the VBA sheet code name is that it can only be changed in the VB environment and is hence safe from a casual user who changes the tab name.

  7. #7
    Forum Contributor
    Join Date
    08-20-2011
    Location
    Oslo
    MS-Off Ver
    MS 365
    Posts
    245

    Re: Copy from static destination & paste to dynamic destination

    Hi!

    I have the following function in cells L6, P6 and T6 to generate random numbers: =RANDBETWEEN(2;27649)

    The numbers go into the VBA below in order to copy and paste varying info from cells J11, N11 and R11 into cells in column F with row numbers corresponding to the randomly generated numbers in L6, P6 and T6, respectively.

    However, I want the randomly generated numbers to have no repeated values for the given range. That is, if a cell in column F is not empty, the row number for that cell will not be generated by the random function, because it has already been used.

    Any ideas on how to solve this?

    Please Login or Register  to view this content.

+ 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 - destination is combo box
    By kl_clifford in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-28-2015, 09:13 AM
  2. Copy and Destination paste value question
    By alexduy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-18-2014, 09:06 PM
  3. Web Query dynamic destination or VBA to copy and paste new data alongside existing data
    By Marbleking in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-12-2012, 06:03 PM
  4. Find, Copy files and Paste in new destination
    By Daniel C in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-01-2012, 12:19 PM
  5. Using destination filepaths listed in cell contents opposing to coding destination
    By kuraitori in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-22-2009, 01:23 PM
  6. [SOLVED] copy paste values only using destination:=
    By Spike in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-12-2006, 07:30 PM

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