Simple VBA to cut and paste

normpam

Active Member
Joined
Oct 30, 2002
Messages
360
I simply need to move the data in any cell from col A to col B.... something is wrong with my syntax. Looking for help, please.

For Each Cell In Range("A2:A33")
If Cell.Value <> Empty Then Cell.Value.Cut Range(Cell).Offset(0, 1)
Next
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
The syntax for cutting the data from column A to column B is incorrect. Try using the following code:

For Each Cell In Range("A2:A33") If Cell.Value <> "" Then Cell.Cut Destination:=Cell.Offset(0, 1) Next

This will loop through each cell in the range A2:A33, check if the cell is not empty, and then cut the contents of the cell and paste it into the cell to the right of it.
 
Upvote 1
The syntax for cutting the data from column A to column B is incorrect. Try using the following code:

For Each Cell In Range("A2:A33") If Cell.Value <> "" Then Cell.Cut Destination:=Cell.Offset(0, 1) Next

This will loop through each cell in the range A2:A33, check if the cell is not empty, and then cut the contents of the cell and paste it into the cell to the right of it.
Thanks. Works fine. I have in the past been able to do a simple copy and paste using code like this:

Range(ActiveCell, ActiveCell).Copy Range(ActiveCell, activecell).Offset(1, 0). Thought it would work the same way with the 'cut' function?
 
Upvote 0
Range(ActiveCell, ActiveCell).Copy is used to copy the content of a single active cell and paste it to another location.

To use the Cut method instead of Copy, you would need to use a similar syntax, like this:
VBA Code:
Range(ActiveCell, ActiveCell).Cut Destination:=Range(ActiveCell, ActiveCell).Offset(1, 0)

You can also use the Cut method on the Value property of a cell, like this:

Code:
ActiveCell.Value.Cut Destination:=ActiveCell.Offset(1, 0)

Please note that, unlike the Copy method, the Cut method will remove the content from the source cell after it is pasted to the destination cell.

Also you can move the data in column A to column B:
Code:
For Each Cell In Range("A2:A33")
    If Cell.Value <> "" Then
        Cell.Value.Cut Destination:=Cell.Offset(0, 1)
    End If
Next
This code loops through each cell in the range A2:A33. If the cell is not empty, it cuts the value and pastes it to the cell in the same row but in column B.
 
Upvote 0
Range(ActiveCell, ActiveCell).Copy is used to copy the content of a single active cell and paste it to another location.

To use the Cut method instead of Copy, you would need to use a similar syntax, like this:
VBA Code:
Range(ActiveCell, ActiveCell).Cut Destination:=Range(ActiveCell, ActiveCell).Offset(1, 0)

You can also use the Cut method on the Value property of a cell, like this:

Code:
ActiveCell.Value.Cut Destination:=ActiveCell.Offset(1, 0)

Please note that, unlike the Copy method, the Cut method will remove the content from the source cell after it is pasted to the destination cell.

Also you can move the data in column A to column B:
Code:
For Each Cell In Range("A2:A33")
    If Cell.Value <> "" Then
        Cell.Value.Cut Destination:=Cell.Offset(0, 1)
    End If
Next
This code loops through each cell in the range A2:A33. If the cell is not empty, it cuts the value and pastes it to the cell in the same row but in column B.
Thanks. I just thought my 'simpler' code might work. No big deal. Have a great night!
 
Upvote 0
Range(ActiveCell, ActiveCell).Copy is used to copy the content of a single active cell and paste it to another location.

To use the Cut method instead of Copy, you would need to use a similar syntax, like this:
VBA Code:
Range(ActiveCell, ActiveCell).Cut Destination:=Range(ActiveCell, ActiveCell).Offset(1, 0)

You can also use the Cut method on the Value property of a cell, like this:

Code:
ActiveCell.Value.Cut Destination:=ActiveCell.Offset(1, 0)

Please note that, unlike the Copy method, the Cut method will remove the content from the source cell after it is pasted to the destination cell.

Also you can move the data in column A to column B:
Code:
For Each Cell In Range("A2:A33")
    If Cell.Value <> "" Then
        Cell.Value.Cut Destination:=Cell.Offset(0, 1)
    End If
Next
This code loops through each cell in the range A2:A33. If the cell is not empty, it cuts the value and pastes it to the cell in the same row but in column B.
Thank you Sinoyon780. i've been looking for this answer for several hours.
 
Upvote 0

Forum statistics

Threads
1,223,953
Messages
6,175,598
Members
452,658
Latest member
GStorm

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