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.
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.
Can you post your code?
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
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.
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))
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?
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.
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.
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
ekr,
Please use code tags with your code as per forum's rule.(Second request)
![]()
Please Login or Register to view this content.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks