Cut and paste macro

gws_gws

New Member
Joined
Jul 28, 2013
Messages
3
I am attempting to cut and paste a fixed number of cells within a column to the first empty column in the sheet. The marco does this, deletes the copied column, and repeats. It works most of the time. Randomly it will paste the cells to a column that is already populated with data.

Here is the code:

Sub Macro1()
'
' Macro1 Macro
'

'

Dim kolumn As Long

Range("C64:C125").Select
Selection.Copy
Range("C1").Select
kolumn = Cells(1, Columns.Count).End(xlToLeft).Column + 1
Cells(1, kolumn).EntireColumn.Select
ActiveSheet.Paste
Rows("64:125").Select
Selection.Delete Shift:=xlUp


End Sub


Any suggestions would be greatly appreciated!
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
I am attempting to cut and paste a fixed number of cells within a column to the first empty column in the sheet. The marco does this, deletes the copied column, and repeats. It works most of the time. Randomly it will paste the cells to a column that is already populated with data.

Here is the code:

Sub Macro1()
'
' Macro1 Macro
'

'

Dim kolumn As Long

Range("C64:C125").Select
Selection.Copy
Range("C1").Select
kolumn = Cells(1, Columns.Count).End(xlToLeft).Column + 1
Cells(1, kolumn).EntireColumn.Select
ActiveSheet.Paste
Rows("64:125").Select
Selection.Delete Shift:=xlUp


End Sub


Any suggestions would be greatly appreciated!

This statement:
kolumn = Cells(1, Columns.Count).End(xlToLeft).Column + 1
only finds the next empty cell on row 1. It does not guarantee that the entire column is blank. If you want a more reliable code to find the last empty column, then try this one. Just make sure there is a value in cell A1 or it will error.
Code:
lastCol = ActiveSheet.Cells.Find(What:="*", After:=ActiveSheet.Range("A1"), LookAt:=xlPart, LookIn:=xlFormulas, _
    SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False).Column
Then use "lastCol + 1" for the empty column.
 
Upvote 0
It does not like LastCol + 1. Editor removes the + sign after I type it.

It shouldn't remove the + if you are using it like this.
Code:
Cells(1, lastCol + 1).EntireColumn.Select
 
Upvote 0

Forum statistics

Threads
1,214,430
Messages
6,119,454
Members
448,898
Latest member
drewmorgan128

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