+ Reply to Thread
Results 1 to 11 of 11

What Linde to put in a Macro in order for that macro to execute twice

  1. #1
    Registered User
    Join Date
    04-02-2013
    Location
    california, usa
    MS-Off Ver
    Excel 2010
    Posts
    33

    What Linde to put in a Macro in order for that macro to execute twice

    I have a macro that copies and pastes a column and its associated rows into the next available blank column. It copies only one - what line can I put in this code so that it executes the macro twice and thereby fills in 2 columns instead of 1.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: What Linde to put in a Macro in order for that macro to execute twice

    Can you post your code?

  3. #3
    Registered User
    Join Date
    04-02-2013
    Location
    california, usa
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: What Linde to put in a Macro in order for that macro to execute twice

    Here is the code -- using Excel 2010

    Please Login or Register  to view this content.
    Last edited by davesexcel; 04-08-2013 at 08:29 PM. Reason: code tags required when displaying code

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: What Linde to put in a Macro in order for that macro to execute twice

    This copies the same column to two columns.
    Range("C29:C51").Copy Range(Cells(29, nEndCl), Cells(51, nEndCl)).Resize(, 2)

    This copies columns C and D to two columns
    Range("C29:D51").Copy Range(Cells(29, nEndCl), Cells(51, nEndCl)).Resize(, 2)
    Last edited by AlphaFrog; 04-08-2013 at 10:04 PM.

  5. #5
    Registered User
    Join Date
    04-02-2013
    Location
    california, usa
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: What Linde to put in a Macro in order for that macro to execute twice

    What can I put in my code to make this execute 4 times, 6 times, 8 times,...
    nEndC1 = Cells(29, Columns.Count).End(xlToLeft).Offset(0, 1).Column
    Range("C29:C51").Copy Range(Cells(29, nEndC1), Cells(51, nEndC1))

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: What Linde to put in a Macro in order for that macro to execute twice

    ekr,
    You can put the number of times a row needs to be copied on in to a separate column. For e.g. in your e.g. 4 goes in to row1, 6 goes in to row and so on, which means row 1 will be copied 4 times and row 2 copied 6 times. Could you attach a sample?

  7. #7
    Registered User
    Join Date
    04-02-2013
    Location
    california, usa
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: What Linde to put in a Macro in order for that macro to execute twice

    The code copies a specific column to the next available blank column, so specifying a row would not work. Here's the code

    Sub CopyDataToAnotherLocation()
    Dim nEndCl As Integer

    nEndCl = Cells(29, Columns.Count).End(xlToLeft).Offset(0, 1).Column

    Range("E29:E51").Copy Range(Cells(29, nEndCl), Cells(51, nEndCl))

    End Sub

    I want to specify the pasting of the column into the next available column, whatever that column may be. I have a need to copy it 4 times, 6 times, 8 times, and maybe up to 16 times.

  8. #8
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: What Linde to put in a Macro in order for that macro to execute twice

    ekr,
    Please use code tags with your code as per forum's rule.
    What is not working for you with your code? It is difficult to see where is your last column is; only sample could resolve the issue.

  9. #9
    Registered User
    Join Date
    04-02-2013
    Location
    california, usa
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: What Linde to put in a Macro in order for that macro to execute twice

    I have revised code to this when I run the code it copies everything in Column C, Rows 29 through 51 to the next available blank column. I cannot upload an example spreadsheet, keep getting an error message "You do not have permission to perform this actio"

    Sub CopyDataToAnotherLocation()
    Dim nEndCl As Integer

    nEndCl = Cells(29, Columns.Count).End(xlToLeft).Offset(0, 1).Column

    Range("C29:C51").Copy Range(Cells(29, nEndCl), Cells(51, nEndCl))

    End Sub

  10. #10
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: What Linde to put in a Macro in order for that macro to execute twice

    ekr,

    Please use code tags with your code as per forum's rule.(Second request)

  11. #11
    Registered User
    Join Date
    04-02-2013
    Location
    california, usa
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: What Linde to put in a Macro in order for that macro to execute twice

    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)

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