paste to next empty column

mahpour4

New Member
Joined
Jul 11, 2012
Messages
47
i have a set of data that i want to copy and paste to the next empty column i have searched all over but cannot find anything that answer my query
this is what i have so far and it doesnt even do columns it does rows
Code:
ActiveSheet.Range("B6:C33").Copy    Sheets(1).Cells(Rows.Count, "A").End(xlUp).Offset (1)
    ActiveSheet.paste Link:=True
    Application.CutCopyMode = False
this is what i have so far and its not working
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Your code will always paste into B column. You need to go from right to left.
Code:
Sub PasteNext()
     ActiveSheet.Range("B6:C33").Copy Sheets(1).Cells([COLOR=#ff0000][B]1[/B][/COLOR], Columns.Count).End(xlToLeft).Offset(1)
     ActiveSheet.Paste Link:=True
     Application.CutCopyMode = False
End Sub
All you need is to adjust the row (highlighted with red color) which the code will use when going from right to left.
 
Upvote 0
probably means
Code:
Sub PasteNext()
     ActiveSheet.Range("B6:C33").Copy Sheets(1).Cells([COLOR=#ff0000][B]1[/B][/COLOR], Columns.Count).End(xlToLeft).Offset([COLOR=red], [/COLOR]1)
     ActiveSheet.Paste Link:=True
     Application.CutCopyMode = False
End Sub
but still has a couple of potential problems.
 
Upvote 0
mirabeau,


Which problems you mean?
1. If the relevant sheet, Sheet(1), is all empty, then with this formulation the paste will be into ColumnB rather than the empty ColumnA.

2. The first empty column may not be the one immediately to the right after the last filled cell in Row 1. Because it may be that Rows 2 or later may have filled cells even further to the right.

Not hard to avoid both of these, but might take a somewhat longer code.
 
Upvote 0
1. If the relevant sheet, Sheet(1), is all empty, then with this formulation the paste will be into ColumnB rather than the empty ColumnA.

2. The first empty column may not be the one immediately to the right after the last filled cell in Row 1. Because it may be that Rows 2 or later may have filled cells even further to the right.

Not hard to avoid both of these, but might take a somewhat longer code.

I have a problem the code doesnt work it gives me a debug by paste statement
 
Last edited:
Upvote 0
I have a problem the code doesnt work it gives me a debug by paste statement
That statement was in your original code.

You didn't say whether or not it worked in your original code, nor whether the modified code otherwise does what you want apart from this error.

If you want to avoid the error statement then try this version
Code:
Sub PasteNext()
On Error Resume Next
     ActiveSheet.Range("B6:C33").Copy Sheets(1).Cells(1, Columns.Count).End(xlToLeft).Offset(, 1)
     ActiveSheet.Paste Link:=True
     Application.CutCopyMode = False
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,340
Members
452,637
Latest member
Ezio2866

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top